Update HEAD in cherry-picking several commits
Without update, index is wrongly detected to be dirty when picking the second commit. Change-Id: Idf47ecb33e8bd38340d760806d629f67be92d2d5 Signed-off-by: Hiroshi Tomita <tomykaira@gmail.com> Bug: 411963
This commit is contained in:
parent
81db591034
commit
27c1c51079
|
@ -111,6 +111,42 @@ public void testCherryPick() throws IOException, JGitInternalException,
|
||||||
assertFalse(history.hasNext());
|
assertFalse(history.hasNext());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testSequentialCherryPick() throws IOException, JGitInternalException,
|
||||||
|
GitAPIException {
|
||||||
|
Git git = new Git(db);
|
||||||
|
|
||||||
|
writeTrashFile("a", "first line\nsec. line\nthird line\n");
|
||||||
|
git.add().addFilepattern("a").call();
|
||||||
|
RevCommit firstCommit = git.commit().setMessage("create a").call();
|
||||||
|
|
||||||
|
writeTrashFile("a", "first line\nsec. line\nthird line\nfourth line\n");
|
||||||
|
git.add().addFilepattern("a").call();
|
||||||
|
RevCommit enlargingA = git.commit().setMessage("enlarged a").call();
|
||||||
|
|
||||||
|
writeTrashFile("a",
|
||||||
|
"first line\nsecond line\nthird line\nfourth line\n");
|
||||||
|
git.add().addFilepattern("a").call();
|
||||||
|
RevCommit fixingA = git.commit().setMessage("fixed a").call();
|
||||||
|
|
||||||
|
git.branchCreate().setName("side").setStartPoint(firstCommit).call();
|
||||||
|
checkoutBranch("refs/heads/side");
|
||||||
|
|
||||||
|
writeTrashFile("b", "nothing to do with a");
|
||||||
|
git.add().addFilepattern("b").call();
|
||||||
|
git.commit().setMessage("create b").call();
|
||||||
|
|
||||||
|
CherryPickResult result = git.cherryPick().include(enlargingA).include(fixingA).call();
|
||||||
|
assertEquals(CherryPickResult.CherryPickStatus.OK, result.getStatus());
|
||||||
|
|
||||||
|
Iterator<RevCommit> history = git.log().call().iterator();
|
||||||
|
assertEquals("fixed a", history.next().getFullMessage());
|
||||||
|
assertEquals("enlarged a", history.next().getFullMessage());
|
||||||
|
assertEquals("create b", history.next().getFullMessage());
|
||||||
|
assertEquals("create a", history.next().getFullMessage());
|
||||||
|
assertFalse(history.hasNext());
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCherryPickDirtyIndex() throws Exception {
|
public void testCherryPickDirtyIndex() throws Exception {
|
||||||
Git git = new Git(db);
|
Git git = new Git(db);
|
||||||
|
|
|
@ -122,9 +122,8 @@ public CherryPickResult call() throws GitAPIException, NoMessageException,
|
||||||
if (headRef == null)
|
if (headRef == null)
|
||||||
throw new NoHeadException(
|
throw new NoHeadException(
|
||||||
JGitText.get().commitOnRepoWithoutHEADCurrentlyNotSupported);
|
JGitText.get().commitOnRepoWithoutHEADCurrentlyNotSupported);
|
||||||
RevCommit headCommit = revWalk.parseCommit(headRef.getObjectId());
|
|
||||||
|
|
||||||
newHead = headCommit;
|
newHead = revWalk.parseCommit(headRef.getObjectId());
|
||||||
|
|
||||||
// loop through all refs to be cherry-picked
|
// loop through all refs to be cherry-picked
|
||||||
for (Ref src : commits) {
|
for (Ref src : commits) {
|
||||||
|
@ -156,12 +155,12 @@ public CherryPickResult call() throws GitAPIException, NoMessageException,
|
||||||
merger.setBase(srcParent.getTree());
|
merger.setBase(srcParent.getTree());
|
||||||
merger.setCommitNames(new String[] { "BASE", ourName,
|
merger.setCommitNames(new String[] { "BASE", ourName,
|
||||||
cherryPickName });
|
cherryPickName });
|
||||||
if (merger.merge(headCommit, srcCommit)) {
|
if (merger.merge(newHead, srcCommit)) {
|
||||||
if (AnyObjectId.equals(headCommit.getTree().getId(), merger
|
if (AnyObjectId.equals(newHead.getTree().getId(), merger
|
||||||
.getResultTreeId()))
|
.getResultTreeId()))
|
||||||
continue;
|
continue;
|
||||||
DirCacheCheckout dco = new DirCacheCheckout(repo,
|
DirCacheCheckout dco = new DirCacheCheckout(repo,
|
||||||
headCommit.getTree(), repo.lockDirCache(),
|
newHead.getTree(), repo.lockDirCache(),
|
||||||
merger.getResultTreeId());
|
merger.getResultTreeId());
|
||||||
dco.setFailOnConflict(true);
|
dco.setFailOnConflict(true);
|
||||||
dco.checkout();
|
dco.checkout();
|
||||||
|
|
Loading…
Reference in New Issue