diff options
author | Robin Stocker <robin@nibor.org> | 2014-08-05 23:38:07 +1000 |
---|---|---|
committer | Robin Stocker <robin@nibor.org> | 2014-08-05 23:38:07 +1000 |
commit | 544f65e655c12cbf7ea8c185cdf59ecee996d9b3 (patch) | |
tree | 61daffa513f3d632e6c50a581086db572e7ca415 /org.eclipse.jgit.test/tst | |
parent | d84661003526167ad474c264a87360d567defda9 (diff) | |
download | jgit-544f65e655c12cbf7ea8c185cdf59ecee996d9b3.tar.gz jgit-544f65e655c12cbf7ea8c185cdf59ecee996d9b3.zip |
Fix CheckoutCommand not setting up tracking
Instead of passing on the start point as is to CreateBranchCommand, the
resolved ObjectId was used. Given this, CreateBranchCommand did not set
up tracking.
This also fixes CreateBranchCommand with setStartPoint(null) to use HEAD
(instead of NPEing), as documented in the Javadoc.
Bug: 441153
Change-Id: I5ed82b4a4b4a32a81a7fa2854636b921bcb3d471
Signed-off-by: Robin Stocker <robin@nibor.org>
Diffstat (limited to 'org.eclipse.jgit.test/tst')
-rw-r--r-- | org.eclipse.jgit.test/tst/org/eclipse/jgit/api/BranchCommandTest.java | 11 | ||||
-rw-r--r-- | org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CheckoutCommandTest.java | 65 |
2 files changed, 59 insertions, 17 deletions
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/BranchCommandTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/BranchCommandTest.java index c0e2e2ca8a..910a645e2b 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/BranchCommandTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/BranchCommandTest.java @@ -473,9 +473,16 @@ public class BranchCommandTest extends RepositoryTestCase { } @Test - public void testCreationImplicitStart() throws JGitInternalException, - GitAPIException { + public void testCreationImplicitStart() throws Exception { git.branchCreate().setName("topic").call(); + assertEquals(db.resolve("HEAD"), db.resolve("topic")); + } + + @Test + public void testCreationNullStartPoint() throws Exception { + String startPoint = null; + git.branchCreate().setName("topic").setStartPoint(startPoint).call(); + assertEquals(db.resolve("HEAD"), db.resolve("topic")); } public Ref createBranch(Git actGit, String name, boolean force, diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CheckoutCommandTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CheckoutCommandTest.java index 614cdd0cef..8487f880f1 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CheckoutCommandTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CheckoutCommandTest.java @@ -56,16 +56,22 @@ import static org.junit.Assert.fail; import java.io.File; import java.io.FileInputStream; import java.io.IOException; +import java.net.MalformedURLException; +import java.net.URISyntaxException; import org.eclipse.jgit.api.CheckoutResult.Status; +import org.eclipse.jgit.api.CreateBranchCommand.SetupUpstreamMode; import org.eclipse.jgit.api.errors.GitAPIException; import org.eclipse.jgit.api.errors.InvalidRefNameException; +import org.eclipse.jgit.api.errors.InvalidRemoteException; import org.eclipse.jgit.api.errors.JGitInternalException; import org.eclipse.jgit.api.errors.RefAlreadyExistsException; import org.eclipse.jgit.api.errors.RefNotFoundException; +import org.eclipse.jgit.api.errors.TransportException; import org.eclipse.jgit.dircache.DirCache; import org.eclipse.jgit.dircache.DirCacheEntry; import org.eclipse.jgit.junit.RepositoryTestCase; +import org.eclipse.jgit.lib.ConfigConstants; import org.eclipse.jgit.lib.Constants; import org.eclipse.jgit.lib.Ref; import org.eclipse.jgit.lib.RefUpdate; @@ -201,29 +207,37 @@ public class CheckoutCommandTest extends RepositoryTestCase { } @Test - public void testCheckoutRemoteTrackingWithoutLocalBranch() throws Exception { - // create second repository - Repository db2 = createWorkRepository(); - Git git2 = new Git(db2); + public void testCheckoutRemoteTrackingWithUpstream() throws Exception { + Repository db2 = createRepositoryWithRemote(); + + Git.wrap(db2).checkout().setCreateBranch(true).setName("test") + .setStartPoint("origin/test") + .setUpstreamMode(SetupUpstreamMode.TRACK).call(); + + assertEquals("refs/heads/test", db2.getRef(Constants.HEAD).getTarget() + .getName()); + StoredConfig config = db2.getConfig(); + assertEquals("origin", config.getString( + ConfigConstants.CONFIG_BRANCH_SECTION, "test", + ConfigConstants.CONFIG_KEY_REMOTE)); + assertEquals("refs/heads/test", config.getString( + ConfigConstants.CONFIG_BRANCH_SECTION, "test", + ConfigConstants.CONFIG_KEY_MERGE)); + } - // setup the second repository to fetch from the first repository - final StoredConfig config = db2.getConfig(); - RemoteConfig remoteConfig = new RemoteConfig(config, "origin"); - URIish uri = new URIish(db.getDirectory().toURI().toURL()); - remoteConfig.addURI(uri); - remoteConfig.update(config); - config.save(); + @Test + public void testCheckoutRemoteTrackingWithoutLocalBranch() throws Exception { + Repository db2 = createRepositoryWithRemote(); - // fetch from first repository - RefSpec spec = new RefSpec("+refs/heads/*:refs/remotes/origin/*"); - git2.fetch().setRemote("origin").setRefSpecs(spec).call(); // checkout remote tracking branch in second repository // (no local branches exist yet in second repository) - git2.checkout().setName("remotes/origin/test").call(); + Git.wrap(db2).checkout().setName("remotes/origin/test").call(); assertEquals("[Test.txt, mode:100644, content:Some change]", indexState(db2, CONTENT)); } + + @Test public void testCheckoutOfFileWithInexistentParentDir() throws Exception { File a = writeTrashFile("dir/a.txt", "A"); @@ -372,6 +386,27 @@ public class CheckoutCommandTest extends RepositoryTestCase { assertEquals(CheckoutResult.NOT_TRIED_RESULT, co.getResult()); } + private Repository createRepositoryWithRemote() throws IOException, + URISyntaxException, MalformedURLException, GitAPIException, + InvalidRemoteException, TransportException { + // create second repository + Repository db2 = createWorkRepository(); + Git git2 = new Git(db2); + + // setup the second repository to fetch from the first repository + final StoredConfig config = db2.getConfig(); + RemoteConfig remoteConfig = new RemoteConfig(config, "origin"); + URIish uri = new URIish(db.getDirectory().toURI().toURL()); + remoteConfig.addURI(uri); + remoteConfig.update(config); + config.save(); + + // fetch from first repository + RefSpec spec = new RefSpec("+refs/heads/*:refs/remotes/origin/*"); + git2.fetch().setRemote("origin").setRefSpecs(spec).call(); + return db2; + } + private CheckoutCommand newOrphanBranchCommand() { return git.checkout().setOrphan(true) .setName("orphanbranch"); |