diff options
author | Chris Aniszczyk <caniszczyk@gmail.com> | 2011-01-26 12:17:47 -0500 |
---|---|---|
committer | Code Review <codereview-daemon@eclipse.org> | 2011-01-26 12:17:47 -0500 |
commit | 9b8ac0151ea1c74ccb04883aa280f4800b53ea64 (patch) | |
tree | 477d08521bf39a89d226dff63e3e354cf3787792 /org.eclipse.jgit | |
parent | 257315d80e1645435371f926adcad48c6e11a1ba (diff) | |
parent | 85f69c286b6c3225dcff05aba42910daefb28da0 (diff) | |
download | jgit-9b8ac0151ea1c74ccb04883aa280f4800b53ea64.tar.gz jgit-9b8ac0151ea1c74ccb04883aa280f4800b53ea64.zip |
Merge "MergeCommand should create missing branches"
Diffstat (limited to 'org.eclipse.jgit')
-rw-r--r-- | org.eclipse.jgit/src/org/eclipse/jgit/api/MergeCommand.java | 27 |
1 files changed, 25 insertions, 2 deletions
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/api/MergeCommand.java b/org.eclipse.jgit/src/org/eclipse/jgit/api/MergeCommand.java index 42e1a51ac9..29ce00e448 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/api/MergeCommand.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/api/MergeCommand.java @@ -131,7 +131,6 @@ public class MergeCommand extends GitCommand<MergeResult> { // Check for FAST_FORWARD, ALREADY_UP_TO_DATE revWalk = new RevWalk(repo); - RevCommit headCommit = revWalk.lookupCommit(head.getObjectId()); // we know for now there is only one commit Ref ref = commits.get(0); @@ -144,6 +143,30 @@ public class MergeCommand extends GitCommand<MergeResult> { objectId = ref.getObjectId(); RevCommit srcCommit = revWalk.lookupCommit(objectId); + + ObjectId headId = head.getObjectId(); + if (headId == null) { + revWalk.parseHeaders(srcCommit); + DirCacheCheckout dco = new DirCacheCheckout(repo, + repo.lockDirCache(), srcCommit.getTree()); + dco.setFailOnConflict(true); + dco.checkout(); + RefUpdate refUpdate = repo + .updateRef(head.getTarget().getName()); + refUpdate.setNewObjectId(objectId); + refUpdate.setExpectedOldObjectId(null); + refUpdate.setRefLogMessage("initial pull", false); + if (refUpdate.update() != Result.NEW) + throw new NoHeadException( + JGitText.get().commitOnRepoWithoutHEADCurrentlyNotSupported); + setCallable(false); + return new MergeResult(srcCommit, srcCommit, new ObjectId[] { + null, srcCommit }, MergeStatus.FAST_FORWARD, + mergeStrategy, null, null); + } + + RevCommit headCommit = revWalk.lookupCommit(headId); + if (revWalk.isMergedInto(srcCommit, headCommit)) { setCallable(false); return new MergeResult(headCommit, srcCommit, new ObjectId[] { @@ -159,7 +182,7 @@ public class MergeCommand extends GitCommand<MergeResult> { dco.setFailOnConflict(true); dco.checkout(); - updateHead(refLogMessage, srcCommit, head.getObjectId()); + updateHead(refLogMessage, srcCommit, headId); setCallable(false); return new MergeResult(srcCommit, srcCommit, new ObjectId[] { headCommit, srcCommit }, MergeStatus.FAST_FORWARD, |