Navigation Menu

Skip to content

Commit

Permalink
Merge pull request #187 from jenkinsci/JENKINS-14026
Browse files Browse the repository at this point in the history
[FIXED JENKINS-14026] git plugin doesn't support branch name contains
  • Loading branch information
ndeloof committed Jan 9, 2014
2 parents b75d1e2 + 13c2b08 commit a67bbc0
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/main/java/hudson/plugins/git/GitSCM.java
Expand Up @@ -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;
Expand Down
14 changes: 14 additions & 0 deletions src/test/java/hudson/plugins/git/GitSCMTest.java
Expand Up @@ -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");
Expand Down

4 comments on commit a67bbc0

@daspilker
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@daspilker
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@ndeloof
Copy link
Contributor Author

@ndeloof ndeloof commented on a67bbc0 Jan 22, 2014 via email

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.