summaryrefslogtreecommitdiff
path: root/builtin
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2021-02-26 00:43:32 (GMT)
committerJunio C Hamano <gitster@pobox.com>2021-02-26 00:43:32 (GMT)
commitd166e8c1d4cb35dec960c4f69ccc23d2fedb322a (patch)
treef29c0d023737722d891005ff41a5f81bbc5d852e /builtin
parentf277234860b2e5e142ab72d2c288f6fd94bd2219 (diff)
parent26c7974376fad730ba5bc1926afe7d26ba8d91e0 (diff)
downloadgit-d166e8c1d4cb35dec960c4f69ccc23d2fedb322a.zip
git-d166e8c1d4cb35dec960c4f69ccc23d2fedb322a.tar.gz
git-d166e8c1d4cb35dec960c4f69ccc23d2fedb322a.tar.bz2
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
Diffstat (limited to 'builtin')
-rw-r--r--builtin/gc.c50
1 files changed, 33 insertions, 17 deletions
diff --git a/builtin/gc.c b/builtin/gc.c
index 6db9cb3..ef7226d 100644
--- a/builtin/gc.c
+++ b/builtin/gc.c
@@ -1461,11 +1461,23 @@ static int maintenance_run(int argc, const char **argv, const char *prefix)
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)
{
+ int rc;
char *config_value;
struct child_process config_set = CHILD_PROCESS_INIT;
struct child_process config_get = CHILD_PROCESS_INIT;
+ char *maintpath = get_maintpath();
/* Disable foreground maintenance */
git_config_set("maintenance.auto", "false");
@@ -1478,40 +1490,44 @@ static int maintenance_register(void)
config_get.git_cmd = 1;
strvec_pushl(&config_get.args, "config", "--global", "--get",
- "--fixed-value", "maintenance.repo",
- the_repository->worktree ? the_repository->worktree
- : the_repository->gitdir,
- NULL);
+ "--fixed-value", "maintenance.repo", maintpath, NULL);
config_get.out = -1;
- if (start_command(&config_get))
- return error(_("failed to run 'git config'"));
+ if (start_command(&config_get)) {
+ rc = error(_("failed to run 'git config'"));
+ goto done;
+ }
/* We already have this value in our config! */
- if (!finish_command(&config_get))
- return 0;
+ if (!finish_command(&config_get)) {
+ rc = 0;
+ goto done;
+ }
config_set.git_cmd = 1;
strvec_pushl(&config_set.args, "config", "--add", "--global", "maintenance.repo",
- the_repository->worktree ? the_repository->worktree
- : the_repository->gitdir,
- NULL);
+ maintpath, NULL);
+
+ rc = run_command(&config_set);
- return run_command(&config_set);
+done:
+ free(maintpath);
+ return rc;
}
static int maintenance_unregister(void)
{
+ int rc;
struct child_process config_unset = CHILD_PROCESS_INIT;
+ char *maintpath = get_maintpath();
config_unset.git_cmd = 1;
strvec_pushl(&config_unset.args, "config", "--global", "--unset",
- "--fixed-value", "maintenance.repo",
- the_repository->worktree ? the_repository->worktree
- : the_repository->gitdir,
- NULL);
+ "--fixed-value", "maintenance.repo", maintpath, NULL);
- return run_command(&config_unset);
+ rc = run_command(&config_unset);
+ free(maintpath);
+ return rc;
}
static const char *get_frequency(enum schedule_priority schedule)