]> git.ipfire.org Git - thirdparty/git.git/commitdiff
scalar: make 'unregister' idempotent
authorDerrick Stolee <derrickstolee@github.com>
Tue, 27 Sep 2022 13:56:59 +0000 (13:56 +0000)
committerJunio C Hamano <gitster@pobox.com>
Tue, 27 Sep 2022 16:32:26 +0000 (09:32 -0700)
The 'scalar unregister' command removes a repository from the list of
registered Scalar repositories and removes it from the list of
repositories registered for background maintenance. If the repository
was not already registered for background maintenance, then the command
fails, even if the repository was still registered as a Scalar
repository.

After using 'scalar clone' or 'scalar register', the repository would be
enrolled in background maintenance since those commands run 'git
maintenance start'. If the user runs 'git maintenance unregister' on
that repository, then it is still in the list of repositories which get
new config updates from 'scalar reconfigure'. The 'scalar unregister'
command would fail since 'git maintenance unregister' would fail.

Further, the add_or_remove_enlistment() method in scalar.c already has
this idempotent nature built in as an expectation since it returns zero
when the scalar.repo list already has the proper containment of the
repository.

The previous change added the 'git maintenance unregister --force'
option, so use it within 'scalar unregister' to make it idempotent.

Signed-off-by: Derrick Stolee <derrickstolee@github.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
scalar.c
t/t9210-scalar.sh

index c5c1ce689199083a9eb47ff6161ce6b1bcd7be64..6de9c0ee523abe56881d9d0158b8ff6a7e07c866 100644 (file)
--- a/scalar.c
+++ b/scalar.c
@@ -207,7 +207,10 @@ static int set_recommended_config(int reconfigure)
 
 static int toggle_maintenance(int enable)
 {
-       return run_git("maintenance", enable ? "start" : "unregister", NULL);
+       return run_git("maintenance",
+                      enable ? "start" : "unregister",
+                      enable ? NULL : "--force",
+                      NULL);
 }
 
 static int add_or_remove_enlistment(int add)
index 14ca575a214f3b74409f89ada717277aeabe5e82..be51a8bb7a4e38e2c53c675850265c6433e905ed 100755 (executable)
@@ -116,7 +116,10 @@ test_expect_success 'scalar unregister' '
        test_must_fail git config --get --global --fixed-value \
                maintenance.repo "$(pwd)/vanish/src" &&
        scalar list >scalar.repos &&
-       ! grep -F "$(pwd)/vanish/src" scalar.repos
+       ! grep -F "$(pwd)/vanish/src" scalar.repos &&
+
+       # scalar unregister should be idempotent
+       scalar unregister vanish
 '
 
 test_expect_success 'set up repository to clone' '