git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: Paul Millar <paul.millar@desy.de>
Cc: git@vger.kernel.org
Subject: Re: bug with git describe --dirty --broken
Date: Thu, 20 Jun 2024 09:57:43 -0700	[thread overview]
Message-ID: <xmqqwmmjwnzs.fsf@gitster.g> (raw)
In-Reply-To: <0fd230f6-a5c5-463d-8584-651ceff3cf99@desy.de> (Paul Millar's message of "Thu, 20 Jun 2024 13:14:24 +0200")

Paul Millar <paul.millar@desy.de> writes:

> When run within the container, git identifies the repo as dirty.  The
> 'podman run' command returns
>
> v1.0.0-dirty
>
> Anything else you want to add:
>
> I believe the problem comes from two parts.
>
> First, when running within the container, the files seemed to be owned
> by user root.
> ...
> This results in an inconsistency between the ownership information
> contained within the .git/index file and the ownership information on
> the filesystem when git is run within the container.

Indeed.  You are running git in two separate environments with
inconsistent worldview.  As many attributes of each file (like the
last modified timestamp and who owns the file) are recorded in the
index for files that were verified to be unmodified (this is done so
that by doing lstat() on a path and comparing the result with the
information saved in the index, we can notice that the path was
modified without actually opening the file and looking at the
contents), after doing something (like "git diff") that causes this
information updated while the files appear to be owned by you,
switching to the alternate world where the files appear to be owned
by root and asking "are these files modified?", Git will trust what
is in the index and report "the index says they are owned by you but
lstat() says otherwise; you must have modified them".

The way we deal with such false positives is to "refresh the index".

And it is done in "git describe --dirty" codepath, but not
"--broken" codepath, which is the cause of the issue you discovered.

There is code snippet in builtin/describe.c that does:

	if (broken) {
		run 'git diff-index' in a subprocess
		use the result from 'diff-index' unless the command
		aborted
	} else if (dirty) {
		refresh the index
		run the equivalent of 'diff-index' in-core
		use the result; if the in-core diff-index aborts,
		you are dead already.
	}

I _think_ the "broken" codepath should be taught to also run "git
update-index --refresh" before it runs "git diff-index" (both in
their own subprocesses, or run in the same subprocess sequencially,
as if "git update-index --refresh && git diff-index" were run), and
your problem may disappear.

Thanks.

  reply	other threads:[~2024-06-20 16:57 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-06-20 11:14 bug with git describe --dirty --broken Paul Millar
2024-06-20 16:57 ` Junio C Hamano [this message]
2024-06-21 12:07   ` Paul Millar
2024-06-21 17:31     ` 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=xmqqwmmjwnzs.fsf@gitster.g \
    --to=gitster@pobox.com \
    --cc=git@vger.kernel.org \
    --cc=paul.millar@desy.de \
    /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).