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

Re: [PATCH] scalar reconfigure -a: remove stale `scalar.repo` entries

From
Derrick Stolee <derrickstolee@github.com>
Date
Nov 7, 2022, 20:14 UTC
Message-ID
<8e4a8817-4fd5-d7f3-2c7d-bf23e61b9823@github.com>
In-Reply-To
<pull.1407.git.1667845501422.gitgitgadget@gmail.com>
On 11/7/22 1:25 PM, Johannes Schindelin via GitGitGadget wrote:
Show 6 quoted lines
> From: Johannes Schindelin <johannes.schindelin@gmx.de>
> 
> Every once in a while, a Git for Windows installation fails because the
> attempt to reconfigure a Scalar enlistment failed because it was deleted
> manually without removing the corresponding entries in the global Git
> config.
Not actually important to this patch: does it actually fail, or does it
just report a warning message (which _looks_ like a failure)?
 
Show 6 quoted lines
> In f5f0842d0b5 (scalar: let 'unregister' handle a deleted enlistment
> directory gracefully, 2021-12-03), we already taught `scalar delete` to
> handle the case of a manually deleted enlistment gracefully. This patch
> adds the same graceful handling to `scalar reconfigure --all`.
> 
> This patch is best viewed with `--color-moved`.
 
Thanks, that did help, even if it's a small change.
Show 22 quoted lines
> @@ -638,8 +656,22 @@ static int cmd_reconfigure(int argc, const char **argv)
>  		strbuf_reset(&gitdir);
>  
>  		if (chdir(dir) < 0) {
> -			warning_errno(_("could not switch to '%s'"), dir);
> -			res = -1;
> +			struct strbuf buf = STRBUF_INIT;
> +
> +			if (errno != ENOENT) {
> +				warning_errno(_("could not switch to '%s'"), dir);
> +				res = -1;
> +				continue;
> +			}
> +
> +			strbuf_addstr(&buf, dir);
> +			if (remove_deleted_enlistment(&buf))
> +				res = error(_("could not remove stale "
> +					      "scalar.repo '%s'"), dir);
> +			else
> +				warning(_("removing stale scalar.repo '%s'"),
> +					dir);
> +			strbuf_release(&buf);
Looks good.
Show 10 quoted lines
> +test_expect_success '`reconfigure -a` removes stale config entries' '
> +	git init stale/src &&
> +	scalar register stale &&
> +	scalar list >scalar.repos &&
> +	grep stale scalar.repos &&
> +	rm -rf stale &&
> +	scalar reconfigure -a &&
> +	scalar list >scalar.repos &&
> +	! grep stale scalar.repos
> +'

In his reply, Taylor mentioned it would be good to check that we still have the correct list of scalar.repos value. I think that might be critical since one "solution" to this problem of a stale repo could be to remove all scalar.repos values (and this test would currently pass).

Please use a `test_cmp` against scalar.repos. Something like this works:

test_expect_success '`reconfigure -a` removes stale config entries' '
	git init stale/src &&
	scalar register stale &&
	scalar list >scalar.repos &&
	grep stale scalar.repos &&
	grep -v stale scalar.repos >expect &&
	rm -rf stale &&
	scalar reconfigure -a &&
	scalar list >scalar.repos &&
	test_cmp expect scalar.repos
'

Thanks, -Stolee

Previous: Taylor Blau
Message 3 of 3 in “scalar reconfigure -a: remove stale `scalar.repo` entries”
  1. scalar reconfigure -a: remove stale `scalar.repo` entriesJohannes Schindelin via GitGitGadget, Nov 7, 2022
  2. Taylor BlauNov 7, 2022
  3. Derrick StoleeNov 7, 2022

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.