Skip to content

Commit

Permalink
[JENKINS-19108] added a test case to verify the fix.
Browse files Browse the repository at this point in the history
  • Loading branch information
kohsuke committed Sep 21, 2013
1 parent 42f15d8 commit 33d7022
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 2 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Expand Up @@ -191,7 +191,7 @@
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>git-client</artifactId>
<version>1.2.0</version>
<version>1.3.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
Expand Down
35 changes: 34 additions & 1 deletion src/test/java/hudson/plugins/git/GitSCMTest.java
Expand Up @@ -6,9 +6,9 @@
import hudson.plugins.git.GitSCM.BuildChooserContextImpl;
import hudson.plugins.git.extensions.GitSCMExtension;
import hudson.plugins.git.extensions.impl.AuthorInChangelog;
import hudson.plugins.git.extensions.impl.LocalBranch;
import hudson.plugins.git.extensions.impl.PreBuildMerge;
import hudson.plugins.git.extensions.impl.RelativeTargetDirectory;
import hudson.plugins.git.UserMergeOptions;
import hudson.plugins.git.util.BuildChooserContext;
import hudson.plugins.git.util.BuildChooserContext.ContextCallable;
import hudson.plugins.parameterizedtrigger.BuildTrigger;
Expand All @@ -20,6 +20,7 @@
import hudson.slaves.DumbSlave;
import hudson.slaves.EnvironmentVariablesNodeProperty.Entry;
import hudson.plugins.git.GitSCM.DescriptorImpl;
import hudson.tools.ToolProperty;
import hudson.util.IOException2;

import com.google.common.base.Function;
Expand All @@ -29,7 +30,12 @@
import org.eclipse.jgit.lib.Constants;
import org.eclipse.jgit.lib.PersonIdent;

import org.eclipse.jgit.lib.Ref;
import org.eclipse.jgit.lib.Repository;
import org.jenkinsci.plugins.gitclient.Git;
import org.jenkinsci.plugins.gitclient.GitClient;
import org.jenkinsci.plugins.gitclient.JGitTool;
import org.jenkinsci.plugins.gitclient.RepositoryCallback;
import org.jvnet.hudson.test.Bug;
import org.jvnet.hudson.test.TestExtension;

Expand Down Expand Up @@ -971,4 +977,31 @@ public void testPleaseDontContinueAnyway() throws Exception {
p.setScm(new GitSCM("https://github.com/cloudbees/coverity-plugin.git")); // inaccessible repository
assertBuildStatus(Result.FAILURE, p.scheduleBuild2(0).get());
}

@Bug(19108)
public void testCheckoutToSpecificBranch() throws Exception {
FreeStyleProject p = createFreeStyleProject();
GitSCM git = new GitSCM("https://github.com/imod/dummy-tester.git");
setupJGit(git);
git.getExtensions().add(new LocalBranch("master"));
p.setScm(git);

FreeStyleBuild b = assertBuildStatusSuccess(p.scheduleBuild2(0));
GitClient gc = Git.with(StreamTaskListener.fromStdout(),null).in(b.getWorkspace()).getClient();
gc.withRepository(new RepositoryCallback<Void>() {
public Void invoke(Repository repo, VirtualChannel channel) throws IOException, InterruptedException {
Ref head = repo.getRef("HEAD");
assertTrue("Detached HEAD",head.isSymbolic());
Ref t = head.getTarget();
assertEquals(t.getName(),"refs/heads/master");

return null;
}
});
}

private void setupJGit(GitSCM git) {
git.gitTool="jgit";
jenkins.getDescriptorByType(GitTool.DescriptorImpl.class).setInstallations(new JGitTool(Collections.<ToolProperty<?>>emptyList()));
}
}

0 comments on commit 33d7022

Please sign in to comment.