Browse Source

Merge "Untracked files should not be included in stash"

stable-3.0
Robin Rosenberg 12 years ago committed by Gerrit Code Review @ Eclipse.org
parent
commit
f37e25e2c3
  1. 1
      org.eclipse.jgit.test/tst/org/eclipse/jgit/api/StashCreateCommandTest.java
  2. 14
      org.eclipse.jgit/src/org/eclipse/jgit/api/StashCreateCommand.java

1
org.eclipse.jgit.test/tst/org/eclipse/jgit/api/StashCreateCommandTest.java

@ -88,6 +88,7 @@ public class StashCreateCommandTest extends RepositoryTestCase {
git.add().addFilepattern("file.txt").call(); git.add().addFilepattern("file.txt").call();
head = git.commit().setMessage("add file").call(); head = git.commit().setMessage("add file").call();
assertNotNull(head); assertNotNull(head);
writeTrashFile("untracked.txt", "content");
} }
/** /**

14
org.eclipse.jgit/src/org/eclipse/jgit/api/StashCreateCommand.java

@ -241,6 +241,7 @@ public class StashCreateCommand extends GitCommand<RevCommit> {
MutableObjectId id = new MutableObjectId(); MutableObjectId id = new MutableObjectId();
List<PathEdit> wtEdits = new ArrayList<PathEdit>(); List<PathEdit> wtEdits = new ArrayList<PathEdit>();
List<String> wtDeletes = new ArrayList<String>(); List<String> wtDeletes = new ArrayList<String>();
boolean hasChanges = false;
do { do {
AbstractTreeIterator headIter = treeWalk.getTree(0, AbstractTreeIterator headIter = treeWalk.getTree(0,
AbstractTreeIterator.class); AbstractTreeIterator.class);
@ -254,9 +255,12 @@ public class StashCreateCommand extends GitCommand<RevCommit> {
new UnmergedPathException( new UnmergedPathException(
indexIter.getDirCacheEntry())); indexIter.getDirCacheEntry()));
if (wtIter != null) { if (wtIter != null) {
if (indexIter != null && wtIter.idEqual(indexIter) if (indexIter == null && headIter == null)
|| headIter != null continue;
&& wtIter.idEqual(headIter)) hasChanges = true;
if (indexIter != null && wtIter.idEqual(indexIter))
continue;
if (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(
@ -278,10 +282,14 @@ public class StashCreateCommand extends GitCommand<RevCommit> {
} }
}); });
} }
hasChanges = true;
if (wtIter == null && headIter != null) if (wtIter == null && headIter != null)
wtDeletes.add(treeWalk.getPathString()); wtDeletes.add(treeWalk.getPathString());
} while (treeWalk.next()); } while (treeWalk.next());
if (!hasChanges)
return null;
String branch = Repository.shortenRefName(head.getTarget() String branch = Repository.shortenRefName(head.getTarget()
.getName()); .getName());

Loading…
Cancel
Save