{"thread":{"id":"23515","subject":"[PATCH v2 2/3] stash: Don't overwrite files that have gone from the index","startedAt":"2010-04-18T18:28:05Z","lastAt":"2010-04-18T23:11:21Z","messageCount":4,"participants":["Charles Bailey","Junio C Hamano"],"isPatch":true,"patchVersion":2,"patchTotal":3},"messages":[{"id":"139828","messageId":"20100418182805.GB29329@hashpling.org","threadId":"23515","inReplyTo":"9eaa7a4672f2010c9e6e3b3f473f1c09abcfcc45.1271614677.git.charles@hashpling.org","subject":"[PATCH v2 2/3] stash: Don't overwrite files that have gone from the index","fromName":"Charles Bailey","fromEmail":"charles@hashpling.org","sentAt":"2010-04-18T18:28:05Z","receivedAt":"2010-04-18T18:28:05Z","isPatch":true,"sender":{"key":"charles@hashpling.org","avatar":"https://avatars.githubusercontent.com/u/1668475?v=4"},"body":"The use of git add -u in create_stash isn't always complete. In\nparticular, if a file has been removed from the index but changed in the\nwork tree it will not be added to the stash's saved work tree tree\nobject. When stash then resets the work tree to match HEAD, any changes\nwill be lost.\n\nTo be complete, any work tree file which differs from HEAD needs to be\nsaved, regardless of whether it still appears in the index or not.\n\nThis is achieved with a combination of a diff against HEAD and a call to\nupdate-index with an explicit list of paths that have changed.\n\nSigned-off-by: Charles Bailey <charles@hashpling.org>\n---\n\nSince the last version of this patch I've followed Jeff King's advice\nand used update-index. This should be much more portable and reliable.\n\nI believe the fix is now complete as it is, although as I noted we\nstill have an issue when stashing file <-> directory changes.\n\n git-stash.sh |    2 +-\n 1 files changed, 1 insertions(+), 1 deletions(-)\n\ndiff --git a/git-stash.sh b/git-stash.sh\nindex 908aab2..1d95447 100755\n--- a/git-stash.sh\n+++ b/git-stash.sh\n@@ -86,7 +86,7 @@ create_stash () {\n \t\t\tGIT_INDEX_FILE=\"$TMP-index\" &&\n \t\t\texport GIT_INDEX_FILE &&\n \t\t\tgit read-tree -m $i_tree &&\n-\t\t\tgit add -u &&\n+\t\t\tgit diff --name-only -z HEAD | git update-index -z --add --remove --stdin &&\n \t\t\tgit write-tree &&\n \t\t\trm -f \"$TMP-index\"\n \t\t) ) ||\n-- \n1.7.1.rc1.241.g4e72f\n"},{"id":"139829","messageId":"20100418182817.GC29329@hashpling.org","threadId":"23515","inReplyTo":"9eaa7a4672f2010c9e6e3b3f473f1c09abcfcc45.1271614677.git.charles@hashpling.org","subject":"[PATCH v2 3/3] Documentation: Describe other situations where -z affects git diff","fromName":"Charles Bailey","fromEmail":"charles@hashpling.org","sentAt":"2010-04-18T18:28:17Z","receivedAt":"2010-04-18T18:28:17Z","isPatch":true,"sender":{"key":"charles@hashpling.org","avatar":"https://avatars.githubusercontent.com/u/1668475?v=4"},"body":"-z also alters the behaviour of --name-only and --name-status.\n\nSigned-off-by: Charles Bailey <charles@hashpling.org>\n---\n\nAs I'm relying on diff --name-only -z \"doing the right thing\", I quite\nwanted it to be part of the documented interface.\n\n Documentation/diff-options.txt |    4 ++--\n 1 files changed, 2 insertions(+), 2 deletions(-)\n\ndiff --git a/Documentation/diff-options.txt b/Documentation/diff-options.txt\nindex 60e922e..c9c6c2b 100644\n--- a/Documentation/diff-options.txt\n+++ b/Documentation/diff-options.txt\n@@ -94,8 +94,8 @@ Also, when `--raw` or `--numstat` has been given, do not munge\n pathnames and use NULs as output field terminators.\n endif::git-log[]\n ifndef::git-log[]\n-\tWhen `--raw` or `--numstat` has been given, do not munge\n-\tpathnames and use NULs as output field terminators.\n+\tWhen `--raw`, `--numstat`, `--name-only` or `--name-status` has been\n+\tgiven, do not munge pathnames and use NULs as output field terminators.\n endif::git-log[]\n +\n Without this option, each pathname output will have TAB, LF, double quotes,\n-- \n1.7.1.rc1.241.g4e72f\n"},{"id":"139845","messageId":"7vbpdgwkw8.fsf@alter.siamese.dyndns.org","threadId":"23515","inReplyTo":"20100418182817.GC29329@hashpling.org","subject":"Re: [PATCH v2 3/3] Documentation: Describe other situations where -z affects git diff","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2010-04-18T20:44:39Z","receivedAt":"2010-04-18T20:44:39Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Charles Bailey <charles@hashpling.org> writes:\n\n> -z also alters the behaviour of --name-only and --name-status.\n>\n> Signed-off-by: Charles Bailey <charles@hashpling.org>\n\nThanks; this is good, independent from the other patches, for 'maint'.\n"},{"id":"139857","messageId":"7vpr1wtkyu.fsf@alter.siamese.dyndns.org","threadId":"23515","inReplyTo":"20100418182805.GB29329@hashpling.org","subject":"Re: [PATCH v2 2/3] stash: Don't overwrite files that have gone from the index","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2010-04-18T23:11:21Z","receivedAt":"2010-04-18T23:11:21Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Charles Bailey <charles@hashpling.org> writes:\n\n> To be complete, any work tree file which differs from HEAD needs to be\n> saved, regardless of whether it still appears in the index or not.\n\nSounds quite sane.\n\n> -\t\t\tgit add -u &&\n> +\t\t\tgit diff --name-only -z HEAD | git update-index -z --add --remove --stdin &&\n\nPaths that exist in HEAD but not in the index will be caught with this;\nwhat about paths that do not exist in HEAD but is in the index---they will\nbe kept in the index so they are fine as well.  Good.\n\nThanks.\n"}]}