# [PATCH v2] maintenance: improve error reporting for unregister

3 messages from 2022-11-11 to 2022-11-14. Participants: Ronan Pigott, Derrick Stolee, Taylor Blau.
Thread: https://gitlist.dev/t/58791

## Ronan Pigott, 2022-11-11 23:19

Subject: [PATCH v2] maintenance: improve error reporting for unregister
Message-ID: <20221111231910.26769-1-ronan@rjp.ie>
URL: https://gitlist.dev/e/20221111231910.26769-1-ronan%40rjp.ie

```
Previously the unregister command would only check the standard paths to
determine if the repo was registered. We should check the provided path
when available instead.

Signed-off-by: Ronan Pigott <ronan@rjp.ie>
---
Changes in v2:
 - Moved configset declaration with the other declarations
 - Extract configset initialization from conditional so it is always
   initialized before it is cleared. It is still deferred until after
   the command arguments are sanity checked.

 Documentation/git-maintenance.txt |  2 +-
 builtin/gc.c                      | 22 ++++++++++++++--------
 t/t7900-maintenance.sh            |  6 +++++-
 3 files changed, 20 insertions(+), 10 deletions(-)

diff --git a/Documentation/git-maintenance.txt b/Documentation/git-maintenance.txt
index eb3ae9fbd599..805e5a2e3a04 100644
--- a/Documentation/git-maintenance.txt
+++ b/Documentation/git-maintenance.txt
@@ -53,7 +53,7 @@ register::
 	Initialize Git config values so any scheduled maintenance will start
 	running on this repository. This adds the repository to the
 	`maintenance.repo` config variable in the current user's global config,
-	or the config specified by --config option, and enables some
+	or the config specified by --config-file option, and enables some
 	recommended configuration values for `maintenance.<task>.schedule`. The
 	tasks that are enabled are safe for running in the background without
 	disrupting foreground processes.
diff --git a/builtin/gc.c b/builtin/gc.c
index 1709355bce5a..c32a5f28cca9 100644
--- a/builtin/gc.c
+++ b/builtin/gc.c
@@ -1543,6 +1543,7 @@ static int maintenance_unregister(int argc, const char **argv, const char *prefi
 	int found = 0;
 	struct string_list_item *item;
 	const struct string_list *list;
+	struct config_set cs;
 
 	argc = parse_options(argc, argv, prefix, options,
 			     builtin_maintenance_unregister_usage, 0);
@@ -1550,19 +1551,23 @@ static int maintenance_unregister(int argc, const char **argv, const char *prefi
 		usage_with_options(builtin_maintenance_unregister_usage,
 				   options);
 
-	if (!config_file) {
+	git_configset_init(&cs);
+	if (config_file) {
+		git_configset_add_file(&cs, config_file);
+		list = git_configset_get_value_multi(&cs, key);
+	} else {
 		list = git_config_get_value_multi(key);
-		if (list) {
-			for_each_string_list_item(item, list) {
-				if (!strcmp(maintpath, item->string)) {
-					found = 1;
-					break;
-				}
+	}
+	if (list) {
+		for_each_string_list_item(item, list) {
+			if (!strcmp(maintpath, item->string)) {
+				found = 1;
+				break;
 			}
 		}
 	}
 
-	if (found || config_file) {
+	if (found) {
 		int rc;
 		char *user_config = NULL, *xdg_config = NULL;
 		if (!config_file) {
@@ -1585,6 +1590,7 @@ static int maintenance_unregister(int argc, const char **argv, const char *prefi
 		die(_("repository '%s' is not registered"), maintpath);
 	}
 
+	git_configset_clear(&cs);
 	free(maintpath);
 	return 0;
 }
diff --git a/t/t7900-maintenance.sh b/t/t7900-maintenance.sh
index 091da683a8af..823331e44a03 100755
--- a/t/t7900-maintenance.sh
+++ b/t/t7900-maintenance.sh
@@ -517,7 +517,11 @@ test_expect_success 'register and unregister' '
 
 	test_must_fail git maintenance unregister 2>err &&
 	grep "is not registered" err &&
-	git maintenance unregister --force
+	git maintenance unregister --force &&
+
+	test_must_fail git maintenance unregister --config-file ./other 2>err &&
+	grep "is not registered" err &&
+	git maintenance unregister --config-file ./other --force
 '
 
 test_expect_success !MINGW 'register and unregister with regex metacharacters' '
-- 
2.38.1


```

## Derrick Stolee, 2022-11-14 15:04

Subject: Re: [PATCH v2] maintenance: improve error reporting for unregister
Message-ID: <2c78ee6b-0ee1-8955-a692-384a238d0f64@github.com>
URL: https://gitlist.dev/e/2c78ee6b-0ee1-8955-a692-384a238d0f64%40github.com
In-Reply-To: <20221111231910.26769-1-ronan@rjp.ie>

```
On 11/11/2022 6:19 PM, Ronan Pigott wrote:
> Previously the unregister command would only check the standard paths to
> determine if the repo was registered. We should check the provided path
> when available instead.

Thank you for following up on these items. I appreciate your diligence.

LGTM.
-Stolee

```

## Taylor Blau, 2022-11-14 22:53

Subject: Re: [PATCH v2] maintenance: improve error reporting for unregister
Message-ID: <Y3LHBL3PpwufjjFx@nand.local>
URL: https://gitlist.dev/e/Y3LHBL3PpwufjjFx%40nand.local
In-Reply-To: <2c78ee6b-0ee1-8955-a692-384a238d0f64@github.com>

```
On Mon, Nov 14, 2022 at 10:04:38AM -0500, Derrick Stolee wrote:
> On 11/11/2022 6:19 PM, Ronan Pigott wrote:
> > Previously the unregister command would only check the standard paths to
> > determine if the repo was registered. We should check the provided path
> > when available instead.
>
> Thank you for following up on these items. I appreciate your diligence.

Thanks, both. Will queue.

Thanks,
Taylor

```
