git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Jeff King <peff@peff.net>
To: git@vger.kernel.org
Cc: Joel Teichroeb <joel@teichroeb.net>,
	Thomas Gummerer <t.gummerer@gmail.com>,
	Johannes Schindelin <Johannes.Schindelin@gmx.de>
Subject: [BUG] builtin "stash apply" does not refresh index
Date: Fri, 23 Aug 2019 01:27:37 -0400	[thread overview]
Message-ID: <20190823052737.GA10592@sigill.intra.peff.net> (raw)

Try this:

  # a repo with one file
  git init repo
  cd repo
  echo base >file
  git add file
  git commit -m base

  # now stash a modification
  echo modified >file
  git stash

  # then make the file stat dirty. This will change inode; on systems
  # without inodes, probably "sleep 1; touch file" would work.
  cp file other
  mv other file

  # now try to apply the stash
  git stash apply

The final command gives me:

  error: Your local changes to the following files would be overwritten by merge:
	file
  Please commit your changes or stash them before you merge.
  Aborting

This started with 8a0fc8d19d (stash: convert apply to builtin,
2019-02-25), which is in v2.22.0. Interestingly, do_stash_apply() does
in fact call refresh_cache(). But it looks like we don't ever write it
out to disk. So when we later call merge_recursive(), it presumably uses
the on-disk index, not what we have in memory.

It's not clear to me where the fix should go, though. Should "stash
apply" be writing out the refreshed index before proceeding? Or should
merge_recursive() be more careful about refreshing the index after it
locks it? The former is what happened with stash as a shell script, but
the latter would save us an otherwise pointless write.

I'm also not sure if other parts of stash might have a similar bug due
to the conversion to C. I think it's an easy mistake when converting
"git update-index --refresh" into "refresh_cache()" and then some other
part of the code takes the index lock (and thus looks at that index, not
what we have in memory).

-Peff

             reply	other threads:[~2019-08-23  5:27 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-08-23  5:27 Jeff King [this message]
2019-08-23 16:56 ` [BUG] builtin "stash apply" does not refresh index 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

  List information: http://vger.kernel.org/majordomo-info.html

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

  git send-email \
    --in-reply-to=20190823052737.GA10592@sigill.intra.peff.net \
    --to=peff@peff.net \
    --cc=Johannes.Schindelin@gmx.de \
    --cc=git@vger.kernel.org \
    --cc=joel@teichroeb.net \
    --cc=t.gummerer@gmail.com \
    /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.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

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 read-only IMAP folder(s) and NNTP newsgroup(s).