Skip to content

Commit d871b6c

Browse files
derrickstoleegitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 1ebe6b0 commit d871b6c

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

scalar.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,10 @@ static int set_recommended_config(int reconfigure)
207207

208208
static int toggle_maintenance(int enable)
209209
{
210-
return run_git("maintenance", enable ? "start" : "unregister", NULL);
210+
return run_git("maintenance",
211+
enable ? "start" : "unregister",
212+
enable ? NULL : "--force",
213+
NULL);
211214
}
212215

213216
static int add_or_remove_enlistment(int add)

t/t9210-scalar.sh

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,10 @@ test_expect_success 'scalar unregister' '
116116
test_must_fail git config --get --global --fixed-value \
117117
maintenance.repo "$(pwd)/vanish/src" &&
118118
scalar list >scalar.repos &&
119-
! grep -F "$(pwd)/vanish/src" scalar.repos
119+
! grep -F "$(pwd)/vanish/src" scalar.repos &&
120+
121+
# scalar unregister should be idempotent
122+
scalar unregister vanish
120123
'
121124

122125
test_expect_success 'set up repository to clone' '

0 commit comments

Comments
 (0)