stash: Don't overwrite files that have gone from the index
A message that is not in the archive (sent off-list or not yet received): 9eaa7a4672f2010c9e6e3b3f473f1c09abcfcc45.1271614677.git.charles@hashpling.org
PATCH v2 2/3 stash: Don't overwrite files that have gone from the 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.
---
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(-)
git-stash.sh +1 -1
@@ -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" ) ) ||
Signature · 1 line
1.7.1.rc1.241.g4e72f
Quoted 2 lines · Charles Bailey
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.
Sounds quite sane.
git-stash.sh create_stash () { · line 89
Quoted 2 lines
git-stash.sh +1
-1- git add -u && + git diff --name-only -z HEAD | git update-index -z --add --remove --stdin &&
Paths that exist in HEAD but not in the index will be caught with this; what about paths that do not exist in HEAD but is in the index---they will be kept in the index so they are fine as well. Good.
Thanks.
PATCH v2 3/3 Documentation: Describe other situations where -z affects git diff
In reply to a message not in the archive-z also alters the behaviour of --name-only and --name-status.
---
As I'm relying on diff --name-only -z "doing the right thing", I quite wanted it to be part of the documented interface.
Documentation/diff-options.txt | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-)
Documentation/diff-options.txt +2 -2
@@ -94,8 +94,8 @@ Also, when `--raw` or `--numstat` has been given, do not munge pathnames and use NULs as output field terminators. endif::git-log[] ifndef::git-log[] - When `--raw` or `--numstat` has been given, do not munge - pathnames and use NULs as output field terminators. + When `--raw`, `--numstat`, `--name-only` or `--name-status` has been + given, do not munge pathnames and use NULs as output field terminators. endif::git-log[] + Without this option, each pathname output will have TAB, LF, double quotes,
Signature · 1 line
1.7.1.rc1.241.g4e72f
Re: [PATCH v2 3/3] Documentation: Describe other situations where -z affects git diff
Quoted 3 lines · Charles Bailey
-z also alters the behaviour of --name-only and --name-status.
Signed-off-by Charles Bailey <[email protected]>
Thanks; this is good, independent from the other patches, for 'maint'.