git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH] git status: do not require write permission

From
Junio C Hamano <gitster@pobox.com>
Date
Jan 20, 2010, 01:09 UTC
Message-ID
<7v8wbt7far.fsf@alter.siamese.dyndns.org>
In-Reply-To
<7vhbqh7gpa.fsf@alter.siamese.dyndns.org>
Junio C Hamano <gitster@pobox.com> writes:
Show 16 quoted lines
> Jeff King <peff@peff.net> writes:
>
>> On Wed, Jan 20, 2010 at 01:06:17AM +0100, Johannes Schindelin wrote:
>>
>>> Today, git status played violin on my nerves for the very last time.
>>> There is no good reason, really none, for git status to require
>>> write permissions.  If the index is not up-to-date, so be it, I
>>> cannot commit anyway.
>>
>> I agree it is annoying, but this patch does not apply (and is no longer
>> needed) on master since the status-is-no-longer-commit-dry-run series
>> has been merged.
>>
>> I don't know if it is worth putting your fix onto maint.
>
> I think the patch itself makes sense,...

Actually, I think it was somewhat a selfish patch and forgot that the codepath is shared with a mode of operation where we should guarantee that the index is updated, namely "git commit".

I think this would be a good addition to 'maint'. I am not sure if it is worth forward-porting to "commit --dry-run", though. On one hand, it might show what would happen if you ran "commit" better (i.e. you will be told that you cannot write into it), but it is debatable if that is the reason why people may want to run "commit --dry-run".

-- >8 --
Subject: status: don't require the repository to be writable

We need to update the index before hooks run when actually making a commit, but we shouldn't have to write the index when running "status". If we can, then we have already spent cycles to refresh the index and it is a waste not to write it out, but it is not a disaster if we cannot write it out. The main reason the user is running "git status" is to get the "status", and refreshing the index is a mere side effect that we can do without.

Discovery and initial attempted fix by Dscho.
---
 builtin-commit.c |   10 ++++++----
 1 files changed, 6 insertions(+), 4 deletions(-)
diff --git a/builtin-commit.c b/builtin-commit.c
index 33aa593..83b7c35 100644
--- a/builtin-commit.c
+++ b/builtin-commit.c
@@ -278,11 +278,13 @@ static char *prepare_index(int argc, const char **argv, const char *prefix, int
 	 * We still need to refresh the index here.
 	 */
 	if (!pathspec || !*pathspec) {
-		fd = hold_locked_index(&index_lock, 1);
+		fd = hold_locked_index(&index_lock, !is_status);
 		refresh_cache(refresh_flags);
-		if (write_cache(fd, active_cache, active_nr) ||
-		    commit_locked_index(&index_lock))
-			die("unable to write new_index file");
+		if (0 <= fd) {
+			if (write_cache(fd, active_cache, active_nr) ||
+			    commit_locked_index(&index_lock))
+				die("unable to write new_index file");
+		}
 		commit_style = COMMIT_AS_IS;
 		return get_index_file();
 	}
Previous: Junio C HamanoNext: Johannes Schindelin
Message 6 of 8 in “git status: do not require write permission”
  1. git status: do not require write permissionJohannes Schindelin, Jan 20, 2010
  2. Jeff KingJan 20, 2010
  3. Johannes SchindelinJan 20, 2010
  4. Johannes SchindelinJan 20, 2010
  5. Junio C HamanoJan 20, 2010
  6. Junio C HamanoJan 20, 2010
  7. Johannes SchindelinJan 20, 2010
  8. Junio C HamanoJan 20, 2010

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.