[PATCH v2 2/3] stash: Don't overwrite files that have gone from the index

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



The use of git add -u in create_stash isn't always complete. In
particular, if a file has been removed from the index but changed in the
work tree it will not be added to the stash's saved work tree tree
object. When stash then resets the work tree to match HEAD, any changes
will be lost.

To be complete, any work tree file which differs from HEAD needs to be
saved, regardless of whether it still appears in the index or not.

This is achieved with a combination of a diff against HEAD and a call to
update-index with an explicit list of paths that have changed.

Signed-off-by: Charles Bailey <charles@xxxxxxxxxxxxx>
---

Since the last version of this patch I've followed Jeff King's advice
and used update-index. This should be much more portable and reliable.

I believe the fix is now complete as it is, although as I noted we
still have an issue when stashing file <-> directory changes.

 git-stash.sh |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/git-stash.sh b/git-stash.sh
index 908aab2..1d95447 100755
--- a/git-stash.sh
+++ b/git-stash.sh
@@ -86,7 +86,7 @@ create_stash () {
 			GIT_INDEX_FILE="$TMP-index" &&
 			export GIT_INDEX_FILE &&
 			git read-tree -m $i_tree &&
-			git add -u &&
+			git diff --name-only -z HEAD | git update-index -z --add --remove --stdin &&
 			git write-tree &&
 			rm -f "$TMP-index"
 		) ) ||
-- 
1.7.1.rc1.241.g4e72f

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]