aboutsummaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit
diff options
context:
space:
mode:
authorChristian Halstrick <christian.halstrick@sap.com>2016-04-29 16:54:23 +0200
committerMatthias Sohn <matthias.sohn@sap.com>2016-05-19 00:04:32 +0200
commitad1548b49ee3954814f95d14e111d5e70c811186 (patch)
treeeb71fe069c3de943bb31e7576c9052cc7c93afbe /org.eclipse.jgit
parent6590c0a92ac987489dfa49281a20e5ea956e043d (diff)
downloadjgit-ad1548b49ee3954814f95d14e111d5e70c811186.tar.gz
jgit-ad1548b49ee3954814f95d14e111d5e70c811186.zip
Fix StashApply regarding handling of untracked files
There was a bug regarding how JGit handled untracked files when applying a stash. Problem was that untracked files are applied by doing a merge of HEAD and untrackedFiles commit with a merge base of the stashed HEAD. That's wrong because the untrackedFiles commit has no parent and contains only the untracked files. Using stashed HEAD as merge base leads to unneccessary conflicts on files not event included in the untrackedFiles commit. Imagine this graph directly before you want to apply a stash which was based on 0. You want to apply the stash on current HEAD commit 5. 5 (HEAD,master) / 0---+ \ \ 1---3 (WIP on master) / 2 (untracked files on master) Imagine for a specific (tracked) file f - commit 0 contains X - HEAD contains Y - commit 2 (the untracked files) does not contain file f A merge of 2 and 5 with a merge base of 0 leads to a conflict. The 5 commit wants to modify the file and the 2 commit wants to delete the file -> conflict. If no merge base is set then the semantic is correct. Thanks to Bow for finding this bug and providing the test case. Bug: 485467 Change-Id: I453fa6ec337f81b2a52c4f51f23044faeec409e6 Also-by: Bow Ruggeri <bow@bow.net> Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
Diffstat (limited to 'org.eclipse.jgit')
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/api/StashApplyCommand.java9
1 files changed, 7 insertions, 2 deletions
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/api/StashApplyCommand.java b/org.eclipse.jgit/src/org/eclipse/jgit/api/StashApplyCommand.java
index 1699b9f3d7..b8ee1ec0b3 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/api/StashApplyCommand.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/api/StashApplyCommand.java
@@ -223,8 +223,13 @@ public class StashApplyCommand extends GitCommand<ObjectId> {
ResolveMerger untrackedMerger = (ResolveMerger) strategy
.newMerger(repo, true);
untrackedMerger.setCommitNames(new String[] {
- "stashed HEAD", "HEAD", "untracked files" }); //$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$
- untrackedMerger.setBase(stashHeadCommit);
+ "null", "HEAD", "untracked files" }); //$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$
+ // There is no common base for HEAD & untracked files
+ // because the commit for untracked files has no parent. If
+ // we use stashHeadCommit as common base (as in the other
+ // merges) we potentially report conflicts for files
+ // which are not even member of untracked files commit
+ untrackedMerger.setBase(null);
boolean ok = untrackedMerger.merge(headCommit,
untrackedCommit);
if (ok)