Merge "Consider working tree changes when stashing newly added files"
This commit is contained in:
commit
4955301fac
|
@ -155,6 +155,18 @@ private List<DiffEntry> diffIndexAgainstHead(final RevCommit commit)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private List<DiffEntry> diffIndexAgainstWorking(final RevCommit commit)
|
||||||
|
throws IOException {
|
||||||
|
TreeWalk walk = createTreeWalk();
|
||||||
|
try {
|
||||||
|
walk.addTree(commit.getParent(1).getTree());
|
||||||
|
walk.addTree(commit.getTree());
|
||||||
|
return DiffEntry.scan(walk);
|
||||||
|
} finally {
|
||||||
|
walk.release();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void noLocalChanges() throws Exception {
|
public void noLocalChanges() throws Exception {
|
||||||
assertNull(git.stashCreate().call());
|
assertNull(git.stashCreate().call());
|
||||||
|
@ -194,6 +206,26 @@ public void indexAdd() throws Exception {
|
||||||
assertEquals("file2.txt", diffs.get(0).getNewPath());
|
assertEquals("file2.txt", diffs.get(0).getNewPath());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void newFileInIndexThenModifiedInWorkTree() throws Exception {
|
||||||
|
writeTrashFile("file", "content");
|
||||||
|
git.add().addFilepattern("file").call();
|
||||||
|
writeTrashFile("file", "content2");
|
||||||
|
RevCommit stashedWorkTree = Git.wrap(db).stashCreate().call();
|
||||||
|
validateStashedCommit(stashedWorkTree);
|
||||||
|
RevWalk walk = new RevWalk(db);
|
||||||
|
RevCommit stashedIndex = stashedWorkTree.getParent(1);
|
||||||
|
walk.parseBody(stashedIndex);
|
||||||
|
walk.parseBody(stashedIndex.getTree());
|
||||||
|
walk.parseBody(stashedIndex.getParent(0));
|
||||||
|
List<DiffEntry> workTreeStashAgainstWorkTree = diffWorkingAgainstHead(stashedWorkTree);
|
||||||
|
assertEquals(1, workTreeStashAgainstWorkTree.size());
|
||||||
|
List<DiffEntry> workIndexAgainstWorkTree = diffIndexAgainstHead(stashedWorkTree);
|
||||||
|
assertEquals(1, workIndexAgainstWorkTree.size());
|
||||||
|
List<DiffEntry> indexStashAgainstWorkTree = diffIndexAgainstWorking(stashedWorkTree);
|
||||||
|
assertEquals(1, indexStashAgainstWorkTree.size());
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void indexDelete() throws Exception {
|
public void indexDelete() throws Exception {
|
||||||
git.rm().addFilepattern("file.txt").call();
|
git.rm().addFilepattern("file.txt").call();
|
||||||
|
|
|
@ -248,13 +248,15 @@ public RevCommit call() throws GitAPIException {
|
||||||
DirCacheIterator.class);
|
DirCacheIterator.class);
|
||||||
WorkingTreeIterator wtIter = treeWalk.getTree(2,
|
WorkingTreeIterator wtIter = treeWalk.getTree(2,
|
||||||
WorkingTreeIterator.class);
|
WorkingTreeIterator.class);
|
||||||
if (headIter != null && indexIter != null && wtIter != null) {
|
if (indexIter != null
|
||||||
if (!indexIter.getDirCacheEntry().isMerged())
|
&& !indexIter.getDirCacheEntry().isMerged())
|
||||||
throw new UnmergedPathsException(
|
throw new UnmergedPathsException(
|
||||||
new UnmergedPathException(
|
new UnmergedPathException(
|
||||||
indexIter.getDirCacheEntry()));
|
indexIter.getDirCacheEntry()));
|
||||||
if (wtIter.idEqual(indexIter)
|
if (wtIter != null) {
|
||||||
|| wtIter.idEqual(headIter))
|
if (indexIter != null && wtIter.idEqual(indexIter)
|
||||||
|
|| headIter != null
|
||||||
|
&& wtIter.idEqual(headIter))
|
||||||
continue;
|
continue;
|
||||||
treeWalk.getObjectId(id, 0);
|
treeWalk.getObjectId(id, 0);
|
||||||
final DirCacheEntry entry = new DirCacheEntry(
|
final DirCacheEntry entry = new DirCacheEntry(
|
||||||
|
@ -271,14 +273,12 @@ public RevCommit call() throws GitAPIException {
|
||||||
in.close();
|
in.close();
|
||||||
}
|
}
|
||||||
wtEdits.add(new PathEdit(entry) {
|
wtEdits.add(new PathEdit(entry) {
|
||||||
|
|
||||||
public void apply(DirCacheEntry ent) {
|
public void apply(DirCacheEntry ent) {
|
||||||
ent.copyMetaData(entry);
|
ent.copyMetaData(entry);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} else if (indexIter == null)
|
}
|
||||||
wtDeletes.add(treeWalk.getPathString());
|
if (wtIter == null && headIter != null)
|
||||||
else if (wtIter == null && headIter != null)
|
|
||||||
wtDeletes.add(treeWalk.getPathString());
|
wtDeletes.add(treeWalk.getPathString());
|
||||||
} while (treeWalk.next());
|
} while (treeWalk.next());
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue