From: Charles Bailey <charles@hashpling.org>
To: Junio C Hamano <gitster@pobox.com>
Cc: git@vger.kernel.org, Thomas Rast <trast@student.ethz.ch>,
Jeff King <peff@peff.net>
Subject: Re: [PATCH v2 1/3] stash bug: stash can lose data in a file removed from the index
Date: Mon, 19 Apr 2010 08:45:20 +0100 [thread overview]
Message-ID: <20100419074520.GA5513@hashpling.org> (raw)
In-Reply-To: <7vvdbotkz0.fsf@alter.siamese.dyndns.org>
On Sun, Apr 18, 2010 at 04:11:15PM -0700, Junio C Hamano wrote:
> Charles Bailey <charles@hashpling.org> writes:
>
> It is likely that this needs to be protected with SYMLINKS prerequisite.
> Also I am a bit unhappy about the use of "readlink" which is not even in
> POSIX.1 here. We already have one use of it in the tests but that only
> happens while doing valgrind. Traditionally this has been more portably
> done by reading from "ls -l file", like so:
>
> case "$(ls -l file)" in *" file -> file2") :;; *) false;; esac
I don't have access to many flavours of unix at the moment and I
failed to look up the POSIXness of readlink. I'll re-roll with greater
portability.
> Also, whether "readlink file" or "ls -l file" is used to check the result,
> the "test -f file" is redundant.
Yes, of course. Not sure what I was thinking.
What about "test -h"? Is this sufficiently portable
for use in our tests? I understand that it's supposed to be POSIX and
available on Solaris sh.
>
> > +test_expect_failure 'stash directory to file' '
> > + git reset --hard &&
> > + mkdir dir &&
> > + echo foo >dir/file &&
> > + git add dir/file &&
> > + git commit -m "Add file in dir" &&
> > + rm dir/file &&
> > + rmdir dir &&
> > + echo bar >dir &&
> > + git stash save "directory to file" &&
> > + test -d dir &&
> > + test foo = "$(cat dir/file)" &&
> > + test_must_fail git stash apply &&
> > + test bar = "$(cat dir)" &&
> > + git reset --soft HEAD^
> > +'
>
> I have a feeling that this test is being a bit unfair.
>
> What should a successful invocation of "stash apply" leave in the working
> tree in this case, especially when you consider that in a real life use
> case you may have other files in "dir" directory or changes to "dir/file"?
Actually I now think that this is completely wrong. There's no reason
that stash apply shouldn't succeed. If we managed to save the new file
where the directory was in the stash then why shouldn't apply be able
to at least attempt to remove the tracked files in the directory that
were originally removed and replace them with the stashed file?
Even if we decide that it can't or shouldn't, we should expect a
failing stash apply to leave the tree as it currently is. That does
leave the question of how the user is supposed to get stuff out of his
stash. After all, he's trying to apply the stash on exactly the state
that stash left him in.
Is it sensible to be guided by these two principles: git stash should
be safe, i.e. it should never remove content that it doesn't save in
the database. git stash && git stash apply should leave the working
tree exactly as it was before the git stash invocation (if the stash
succeeds it may be equivalent to a git reset)?
If so we definitely need to fix the behaviour where git stash
vaporizes local changes when there's a file <-> directory change
in the working tree. Even if we cop out and make git stash fail if it
determines that it wouldn't restore the changes.
Charles.
prev parent reply other threads:[~2010-04-19 7:45 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-04-18 18:27 [PATCH v2 1/3] stash bug: stash can lose data in a file removed from the index Charles Bailey
2010-04-18 23:11 ` Junio C Hamano
2010-04-19 7:45 ` Charles Bailey [this message]
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=20100419074520.GA5513@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).