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

Re: [PATCH] builtin/stash: report failure to write to index

From
Junio C Hamano <gitster@pobox.com>
Date
Feb 6, 2024, 03:24 UTC
Message-ID
<xmqqo7cul1fi.fsf@gitster.g>
In-Reply-To
<2cd44b01dc29b099a07658499481a6847c46562d.1707116449.git.ps@pks.im>
Patrick Steinhardt <ps@pks.im> writes:
Show 6 quoted lines
> The git-stash(1) command needs to write to the index for many of its
> operations. When the index is locked by a concurrent writer it will thus
> fail to operate, which is expected. What is not expected though is that
> we do not print any error message at all in this case. The user can thus
> easily miss the fact that the command didn't do what they expected it to
> do and would be left wondering why that is.

Hopefully, they know they notice the exit status of the command, or do we throw the error away and exit(0) from the program?

In any case, telling the users what did (and did not) happen is a good idea.

Show 7 quoted lines
> Fix this bug and report failures to write to the index. Add tests for
> the subcommands which hit the respective code paths.
>
> Note that the chosen error message ("Cannot write to the index") does
> not match our guidelines as it starts with a capitalized letter. This is
> intentional though and matches the style of all the other messages used
> in git-stash(1).

Style may be OK, but I wonder if they should say different things, to hint what failed. For example:

Show 9 quoted lines
> @@ -537,7 +537,7 @@ static int do_apply_stash(const char *prefix, struct stash_info *info,
>  	repo_read_index_preload(the_repository, NULL, 0);
>  	if (repo_refresh_and_write_index(the_repository, REFRESH_QUIET, 0, 0,
>  					 NULL, NULL, NULL))
> -		return -1;
> +		return error(_("Cannot write to the index"));
>
>  	if (write_index_as_tree(&c_tree, &the_index, get_index_file(), 0,
>  				NULL))

This failure and message comes before anything interesting happens. We attempted to refresh the current index and failed to write out the result, meaning that whatever index we had on disk did not get overwritten. Is this new message enough to tell the user that we didn't touch the working tree or the index, which would happen if even some part of "stash apply" happened? Or is it obvious that we did not do anything?

Show 8 quoted lines
> @@ -1364,7 +1364,7 @@ static int do_create_stash(const struct pathspec *ps, struct strbuf *stash_msg_b
>  	repo_read_index_preload(the_repository, NULL, 0);
>  	if (repo_refresh_and_write_index(the_repository, REFRESH_QUIET, 0, 0,
>  					 NULL, NULL, NULL) < 0) {
> -		ret = -1;
> +		ret = error(_("Cannot write to the index"));
>  		goto done;
>  	}
Ditto.
Show 9 quoted lines
> @@ -1555,7 +1555,7 @@ static int do_push_stash(const struct pathspec *ps, const char *stash_msg, int q
>  
>  	if (repo_refresh_and_write_index(the_repository, REFRESH_QUIET, 0, 0,
>  					 NULL, NULL, NULL)) {
> -		ret = -1;
> +		ret = error(_("Cannot write to the index"));
>  		goto done;
>  	}
>  
Ditto.
Thanks.
Previous: Patrick SteinhardtNext: Patrick Steinhardt
Message 6 of 8 in “git bug”
  1. moti sdFeb 4, 2024
  2. Patrick SteinhardtFeb 5, 2024
  3. builtin/stash: report failure to write to indexPatrick Steinhardt, Feb 5, 2024
  4. Rubén JustoFeb 5, 2024
  5. Patrick SteinhardtFeb 6, 2024
  6. Junio C HamanoFeb 6, 2024
  7. Patrick SteinhardtFeb 6, 2024
  8. builtin/stash: report failure to write to indexPatrick Steinhardt, Feb 6, 2024

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.