diff options
author | Thomas Wolf <twolf@apache.org> | 2023-04-23 21:34:37 +0200 |
---|---|---|
committer | Thomas Wolf <twolf@apache.org> | 2023-04-29 13:24:58 +0200 |
commit | 8c0c96e0a7e88a12cb4478fc5983680e24c34855 (patch) | |
tree | 100f4f2d92886193a5f9fb8a70bcca7602ec94eb /org.eclipse.jgit | |
parent | 8bc13fb79d3ff44f09b67a1effda7155b47391ae (diff) | |
download | jgit-8c0c96e0a7e88a12cb4478fc5983680e24c34855.tar.gz jgit-8c0c96e0a7e88a12cb4478fc5983680e24c34855.zip |
Support rebasing independent branches
With completely independent branches, there is no merge base. In this
case, the list of commits must include the root commit of the branch to
be rebased.
Bug: 581832
Change-Id: I0f5bdf179d5b07ff09f1a274d61c7a0b1c0011c6
Signed-off-by: Thomas Wolf <twolf@apache.org>
Diffstat (limited to 'org.eclipse.jgit')
-rw-r--r-- | org.eclipse.jgit/src/org/eclipse/jgit/api/RebaseCommand.java | 30 |
1 files changed, 19 insertions, 11 deletions
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/api/RebaseCommand.java b/org.eclipse.jgit/src/org/eclipse/jgit/api/RebaseCommand.java index 1e5523f275..19fd3bb2c4 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/api/RebaseCommand.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/api/RebaseCommand.java @@ -1217,7 +1217,7 @@ public class RebaseCommand extends GitCommand<RebaseResult> { Iterator<RevCommit> commitsToUse = r.iterator(); while (commitsToUse.hasNext()) { RevCommit commit = commitsToUse.next(); - if (preserveMerges || commit.getParentCount() == 1) { + if (preserveMerges || commit.getParentCount() <= 1) { cherryPickList.add(commit); } } @@ -1234,23 +1234,31 @@ public class RebaseCommand extends GitCommand<RebaseResult> { walk.markStart(upstreamCommit); walk.markStart(headCommit); RevCommit base; - while ((base = walk.next()) != null) + while ((base = walk.next()) != null) { RebaseState.createFile(rewrittenDir, base.getName(), upstreamCommit.getName()); - + } Iterator<RevCommit> iterator = cherryPickList.iterator(); pickLoop: while(iterator.hasNext()){ RevCommit commit = iterator.next(); - for (int i = 0; i < commit.getParentCount(); i++) { - boolean parentRewritten = new File(rewrittenDir, commit - .getParent(i).getName()).exists(); - if (parentRewritten) { - new File(rewrittenDir, commit.getName()).createNewFile(); - continue pickLoop; + int nOfParents = commit.getParentCount(); + if (nOfParents == 0) { + // Must be the very first commit in the cherryPickList. We + // have independent branches. + new File(rewrittenDir, commit.getName()).createNewFile(); + } else { + for (int i = 0; i < nOfParents; i++) { + boolean parentRewritten = new File(rewrittenDir, + commit.getParent(i).getName()).exists(); + if (parentRewritten) { + new File(rewrittenDir, commit.getName()) + .createNewFile(); + continue pickLoop; + } } + // commit is only merged in, needs not be rewritten + iterator.remove(); } - // commit is only merged in, needs not be rewritten - iterator.remove(); } } return cherryPickList; |