Skip to content
Permalink
Browse files

Merge pull request #187 from jenkinsci/JENKINS-14026

[FIXED JENKINS-14026] git plugin doesn't support branch name contains
  • Loading branch information...
ndeloof committed Jan 9, 2014
2 parents b75d1e2 + 13c2b08 commit a67bbc0062fa4dd4d27b8113f3a27840b53dded9
Showing with 18 additions and 0 deletions.
  1. +4 −0 src/main/java/hudson/plugins/git/GitSCM.java
  2. +14 −0 src/test/java/hudson/plugins/git/GitSCMTest.java
@@ -435,6 +435,10 @@ private String getSingleBranch(EnvVars env) {
// Check for empty string - replace with "**" when seen.
if (branch.equals("")) {
branch = "**";
} else if (!branch.startsWith(repository)) {
// we can hit this case if the given branch name contains a slash.
// Since we have a single repository, it makes sense to prepend it anyway
branch = repository + "/" + branch;
}

return branch;
@@ -494,6 +494,20 @@ public void testBranchIsAvailableInEvironment() throws Exception {
assertEquals("origin/master", getEnvVars(project).get(GitSCM.GIT_BRANCH));
}

public void testBranchContainsSlash() throws Exception {
FreeStyleProject project = setupSimpleProject("my/branch");

final String commitFile1 = "commitFile1";
commit(commitFile1, johnDoe, "Commit number 1");
git.branch("my/branch");
git.checkout("my/branch");
final String commitFile2 = "commitFile2";
commit(commitFile2, johnDoe, "Commit number 2");
build(project, Result.SUCCESS, commitFile1, commitFile2);

assertEquals("origin/my/branch", getEnvVars(project).get(GitSCM.GIT_BRANCH));
}

// For HUDSON-7411
public void testNodeEnvVarsAvailable() throws Exception {
FreeStyleProject project = setupSimpleProject("master");

4 comments on commit a67bbc0

@daspilker

This comment has been minimized.

Copy link
Member

replied Jan 22, 2014

This breaks the ability the checkout a tag. Now the tag is completed to repo/tag, e.g. origin/git-2.0.1, which can't be checked out.

ERROR: Couldn't find any revision to build. Verify the repository and branch configuration for this job.
Finished: FAILURE

The command line says:

>git checkout origin/git-2.0.1
error: pathspec 'origin/git-2.0.1' did not match any file(s) known to git.
@ndeloof

This comment has been minimized.

Copy link
Member Author

replied Jan 22, 2014

nice catch, reverted as f15d63e
I miss a better test suite to avoid such mistakes :'(

@daspilker

This comment has been minimized.

Copy link
Member

replied Jan 22, 2014

No problem. Are you sure, you picked the right commit? f15d63e reverts the version bump.

@ndeloof

This comment has been minimized.

Copy link
Member Author

replied Jan 22, 2014

Please sign in to comment.
You can’t perform that action at this time.