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 | |
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')
-rw-r--r-- | org.eclipse.jgit/src/org/eclipse/jgit/api/CheckoutCommand.java | 25 | ||||
-rw-r--r-- | org.eclipse.jgit/src/org/eclipse/jgit/api/CreateBranchCommand.java | 22 |
2 files changed, 22 insertions, 25 deletions
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/api/CheckoutCommand.java b/org.eclipse.jgit/src/org/eclipse/jgit/api/CheckoutCommand.java index 77106f415e..0eb25cf11d 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/api/CheckoutCommand.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/api/CheckoutCommand.java @@ -213,7 +213,10 @@ public class CheckoutCommand extends GitCommand<Ref> { Git git = new Git(repo); CreateBranchCommand command = git.branchCreate(); command.setName(name); - command.setStartPoint(getStartPoint().name()); + if (startCommit != null) + command.setStartPoint(startCommit); + else + command.setStartPoint(startPoint); if (upstreamMode != null) command.setUpstreamMode(upstreamMode); command.call(); @@ -234,7 +237,7 @@ public class CheckoutCommand extends GitCommand<Ref> { this.status = CheckoutResult.NOT_TRIED_RESULT; return repo.getRef(Constants.HEAD); } - branch = getStartPoint(); + branch = getStartPointObjectId(); } else { branch = repo.resolve(name); if (branch == null) @@ -386,7 +389,7 @@ public class CheckoutCommand extends GitCommand<Ref> { if (isCheckoutIndex()) checkoutPathsFromIndex(treeWalk, dc); else { - RevCommit commit = revWalk.parseCommit(getStartPoint()); + RevCommit commit = revWalk.parseCommit(getStartPointObjectId()); checkoutPathsFromCommit(treeWalk, dc, commit); } } finally { @@ -468,21 +471,17 @@ public class CheckoutCommand extends GitCommand<Ref> { return startCommit == null && startPoint == null; } - private ObjectId getStartPoint() throws AmbiguousObjectException, + private ObjectId getStartPointObjectId() throws AmbiguousObjectException, RefNotFoundException, IOException { if (startCommit != null) return startCommit.getId(); - ObjectId result = null; - try { - result = repo.resolve((startPoint == null) ? Constants.HEAD - : startPoint); - } catch (AmbiguousObjectException e) { - throw e; - } + + String startPointOrHead = (startPoint != null) ? startPoint + : Constants.HEAD; + ObjectId result = repo.resolve(startPointOrHead); if (result == null) throw new RefNotFoundException(MessageFormat.format( - JGitText.get().refNotResolved, - startPoint != null ? startPoint : Constants.HEAD)); + JGitText.get().refNotResolved, startPointOrHead)); return result; } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/api/CreateBranchCommand.java b/org.eclipse.jgit/src/org/eclipse/jgit/api/CreateBranchCommand.java index 92e8b466b0..a4ad2c9bfb 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/api/CreateBranchCommand.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/api/CreateBranchCommand.java @@ -133,7 +133,7 @@ public class CreateBranchCommand extends GitCommand<Ref> { throw new RefAlreadyExistsException(MessageFormat.format( JGitText.get().refAlreadyExists1, name)); - ObjectId startAt = getStartPoint(); + ObjectId startAt = getStartPointObjectId(); String startPointFullName = null; if (startPoint != null) { Ref baseRef = repo.getRef(startPoint); @@ -151,7 +151,7 @@ public class CreateBranchCommand extends GitCommand<Ref> { baseCommit = startCommit.getShortMessage(); else { RevCommit commit = revWalk.parseCommit(repo - .resolve(startPoint)); + .resolve(getStartPointOrHead())); baseCommit = commit.getShortMessage(); } if (exists) @@ -275,24 +275,22 @@ public class CreateBranchCommand extends GitCommand<Ref> { } } - private ObjectId getStartPoint() throws AmbiguousObjectException, + private ObjectId getStartPointObjectId() throws AmbiguousObjectException, RefNotFoundException, IOException { if (startCommit != null) return startCommit.getId(); - ObjectId result = null; - try { - result = repo.resolve((startPoint == null) ? Constants.HEAD - : startPoint); - } catch (AmbiguousObjectException e) { - throw e; - } + String startPointOrHead = getStartPointOrHead(); + ObjectId result = repo.resolve(startPointOrHead); if (result == null) throw new RefNotFoundException(MessageFormat.format( - JGitText.get().refNotResolved, - startPoint != null ? startPoint : Constants.HEAD)); + JGitText.get().refNotResolved, startPointOrHead)); return result; } + private String getStartPointOrHead() { + return startPoint != null ? startPoint : Constants.HEAD; + } + private void processOptions() throws InvalidRefNameException { if (name == null || !Repository.isValidRefName(Constants.R_HEADS + name)) |