scalar: make 'unregister' idempotent

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>
This commit is contained in:
Derrick Stolee 2022-09-27 13:56:59 +00:00 committed by Junio C Hamano
parent 1ebe6b0297
commit d871b6c6c6
2 changed files with 8 additions and 2 deletions

View File

@ -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)

View File

@ -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' '