git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Charles Bailey <charles@hashpling.org>
To: git@vger.kernel.org, Junio C Hamano <gitster@pobox.com>,
	Thomas Rast <trast@student.ethz.ch>, Jeff King <peff@peff.net>
Subject: [PATCH v2 2/3] stash: Don't overwrite files that have gone from the index
Date: Sun, 18 Apr 2010 19:28:05 +0100	[thread overview]
Message-ID: <20100418182805.GB29329@hashpling.org> (raw)
In-Reply-To: <9eaa7a4672f2010c9e6e3b3f473f1c09abcfcc45.1271614677.git.charles@hashpling.org>

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@hashpling.org>
---

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

       reply	other threads:[~2010-04-18 18:28 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <9eaa7a4672f2010c9e6e3b3f473f1c09abcfcc45.1271614677.git.charles@hashpling.org>
2010-04-18 18:28 ` Charles Bailey [this message]
2010-04-18 23:11   ` [PATCH v2 2/3] stash: Don't overwrite files that have gone from the index Junio C Hamano
2010-04-18 18:28 ` [PATCH v2 3/3] Documentation: Describe other situations where -z affects git diff Charles Bailey
2010-04-18 20:44   ` Junio C Hamano

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20100418182805.GB29329@hashpling.org \
    --to=charles@hashpling.org \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=peff@peff.net \
    --cc=trast@student.ethz.ch \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).