Browse Source

Merge branch 'es/maintenance-of-bare-repositories'

The "git maintenance register" command had trouble registering bare
repositories, which had been corrected.

* es/maintenance-of-bare-repositories:
  maintenance: fix incorrect `maintenance.repo` path with bare repository
maint
Junio C Hamano 4 years ago
parent
commit
d166e8c1d4
  1. 50
      builtin/gc.c
  2. 13
      t/t7900-maintenance.sh

50
builtin/gc.c

@ -1461,11 +1461,23 @@ static int maintenance_run(int argc, const char **argv, const char *prefix)
return maintenance_run_tasks(&opts); return maintenance_run_tasks(&opts);
} }


static char *get_maintpath(void)
{
struct strbuf sb = STRBUF_INIT;
const char *p = the_repository->worktree ?
the_repository->worktree : the_repository->gitdir;

strbuf_realpath(&sb, p, 1);
return strbuf_detach(&sb, NULL);
}

static int maintenance_register(void) static int maintenance_register(void)
{ {
int rc;
char *config_value; char *config_value;
struct child_process config_set = CHILD_PROCESS_INIT; struct child_process config_set = CHILD_PROCESS_INIT;
struct child_process config_get = CHILD_PROCESS_INIT; struct child_process config_get = CHILD_PROCESS_INIT;
char *maintpath = get_maintpath();


/* Disable foreground maintenance */ /* Disable foreground maintenance */
git_config_set("maintenance.auto", "false"); git_config_set("maintenance.auto", "false");
@ -1478,40 +1490,44 @@ static int maintenance_register(void)


config_get.git_cmd = 1; config_get.git_cmd = 1;
strvec_pushl(&config_get.args, "config", "--global", "--get", strvec_pushl(&config_get.args, "config", "--global", "--get",
"--fixed-value", "maintenance.repo", "--fixed-value", "maintenance.repo", maintpath, NULL);
the_repository->worktree ? the_repository->worktree
: the_repository->gitdir,
NULL);
config_get.out = -1; config_get.out = -1;


if (start_command(&config_get)) if (start_command(&config_get)) {
return error(_("failed to run 'git config'")); rc = error(_("failed to run 'git config'"));
goto done;
}


/* We already have this value in our config! */ /* We already have this value in our config! */
if (!finish_command(&config_get)) if (!finish_command(&config_get)) {
return 0; rc = 0;
goto done;
}


config_set.git_cmd = 1; config_set.git_cmd = 1;
strvec_pushl(&config_set.args, "config", "--add", "--global", "maintenance.repo", strvec_pushl(&config_set.args, "config", "--add", "--global", "maintenance.repo",
the_repository->worktree ? the_repository->worktree maintpath, NULL);
: the_repository->gitdir,
NULL);


return run_command(&config_set); rc = run_command(&config_set);

done:
free(maintpath);
return rc;
} }


static int maintenance_unregister(void) static int maintenance_unregister(void)
{ {
int rc;
struct child_process config_unset = CHILD_PROCESS_INIT; struct child_process config_unset = CHILD_PROCESS_INIT;
char *maintpath = get_maintpath();


config_unset.git_cmd = 1; config_unset.git_cmd = 1;
strvec_pushl(&config_unset.args, "config", "--global", "--unset", strvec_pushl(&config_unset.args, "config", "--global", "--unset",
"--fixed-value", "maintenance.repo", "--fixed-value", "maintenance.repo", maintpath, NULL);
the_repository->worktree ? the_repository->worktree
: the_repository->gitdir,
NULL);


return run_command(&config_unset); rc = run_command(&config_unset);
free(maintpath);
return rc;
} }


static const char *get_frequency(enum schedule_priority schedule) static const char *get_frequency(enum schedule_priority schedule)

13
t/t7900-maintenance.sh

@ -632,4 +632,17 @@ test_expect_success 'fails when running outside of a repository' '
nongit test_must_fail git maintenance unregister nongit test_must_fail git maintenance unregister
' '


test_expect_success 'register and unregister bare repo' '
test_when_finished "git config --global --unset-all maintenance.repo || :" &&
test_might_fail git config --global --unset-all maintenance.repo &&
git init --bare barerepo &&
(
cd barerepo &&
git maintenance register &&
git config --get --global --fixed-value maintenance.repo "$(pwd)" &&
git maintenance unregister &&
test_must_fail git config --global --get-all maintenance.repo
)
'

test_done test_done

Loading…
Cancel
Save