]> source.dussan.org Git - jgit.git/commitdiff
Untracked files should not be included in stash 40/12040/1
authorRobin Rosenberg <robin.rosenberg@dewire.com>
Thu, 18 Apr 2013 21:19:15 +0000 (23:19 +0200)
committerRobin Rosenberg <robin.rosenberg@dewire.com>
Thu, 18 Apr 2013 21:19:15 +0000 (23:19 +0200)
The previous code stashed untracked files and left them
in the work tree.

Bug: 403282
Change-Id: I71727addb2b55fb8e409cae2b6af8138b1ff7ef1

org.eclipse.jgit.test/tst/org/eclipse/jgit/api/StashCreateCommandTest.java
org.eclipse.jgit/src/org/eclipse/jgit/api/StashCreateCommand.java

index 544d591fe9764784730e96803383eb4b99263712..322d47a091ce68464963769c6930f3f80dcd172c 100644 (file)
@@ -88,6 +88,7 @@ public class StashCreateCommandTest extends RepositoryTestCase {
                git.add().addFilepattern("file.txt").call();
                head = git.commit().setMessage("add file").call();
                assertNotNull(head);
+               writeTrashFile("untracked.txt", "content");
        }
 
        /**
index ba56c1a7123af061664f427bf6bfad1f6f3d958d..fc21b919b69d4aab5af61b4e366e3b3ed495f40d 100644 (file)
@@ -241,6 +241,7 @@ public class StashCreateCommand extends GitCommand<RevCommit> {
                                MutableObjectId id = new MutableObjectId();
                                List<PathEdit> wtEdits = new ArrayList<PathEdit>();
                                List<String> wtDeletes = new ArrayList<String>();
+                               boolean hasChanges = false;
                                do {
                                        AbstractTreeIterator headIter = treeWalk.getTree(0,
                                                        AbstractTreeIterator.class);
@@ -254,9 +255,12 @@ public class StashCreateCommand extends GitCommand<RevCommit> {
                                                                new UnmergedPathException(
                                                                                indexIter.getDirCacheEntry()));
                                        if (wtIter != null) {
-                                               if (indexIter != null && wtIter.idEqual(indexIter)
-                                                               || headIter != null
-                                                               && wtIter.idEqual(headIter))
+                                               if (indexIter == null && headIter == null)
+                                                       continue;
+                                               hasChanges = true;
+                                               if (indexIter != null && wtIter.idEqual(indexIter))
+                                                       continue;
+                                               if (headIter != null && wtIter.idEqual(headIter))
                                                        continue;
                                                treeWalk.getObjectId(id, 0);
                                                final DirCacheEntry entry = new DirCacheEntry(
@@ -278,10 +282,14 @@ public class StashCreateCommand extends GitCommand<RevCommit> {
                                                        }
                                                });
                                        }
+                                       hasChanges = true;
                                        if (wtIter == null && headIter != null)
                                                wtDeletes.add(treeWalk.getPathString());
                                } while (treeWalk.next());
 
+                               if (!hasChanges)
+                                       return null;
+
                                String branch = Repository.shortenRefName(head.getTarget()
                                                .getName());