From: "Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>
To: git@vger.kernel.org
Cc: "Junio C Hamano" <gitster@pobox.com>,
git@drmicha.warpmail.net, Jens.Lehmann@web.de,
larsxschneider@gmail.com, sbeller@google.com,
mhagger@alum.mit.edu, max@max630.net,
"Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>
Subject: [PATCH v5 3/4] config: automatically migrate to new config layout when --worktree is used
Date: Tue, 10 Jan 2017 18:25:23 +0700 [thread overview]
Message-ID: <20170110112524.12870-4-pclouds@gmail.com> (raw)
In-Reply-To: <20170110112524.12870-1-pclouds@gmail.com>
It's not fun to ask the user to set extensions.worktreeConfig manually.
It's error-prone too. So we do it automatically whenever anybody sets a
per-worktree config with "git config" (support for builtin commands is
coming later).
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
Documentation/git-worktree.txt | 6 ++++++
builtin/config.c | 3 ++-
worktree.c | 40 ++++++++++++++++++++++++++++++++++++++++
worktree.h | 6 ++++++
4 files changed, 54 insertions(+), 1 deletion(-)
diff --git a/Documentation/git-worktree.txt b/Documentation/git-worktree.txt
index 329a673..f5aad0a 100644
--- a/Documentation/git-worktree.txt
+++ b/Documentation/git-worktree.txt
@@ -167,6 +167,12 @@ want to share to all working directories:
you are sure you always use sparse checkout for all working
directories.
+When `git config --worktree` is used to set a configuration variable
+in multiple working directory setup, `extensions.worktreeConfig` will
+be automatically set. The two variables `core.worktree` and
+`core.bare` if present will be moved to `config.worktree` of the main
+working tree.
+
DETAILS
-------
Each linked working tree has a private sub-directory in the repository's
diff --git a/builtin/config.c b/builtin/config.c
index 7d390af..9dafefd 100644
--- a/builtin/config.c
+++ b/builtin/config.c
@@ -533,7 +533,8 @@ int cmd_config(int argc, const char **argv, const char *prefix)
if (repository_format_worktree_config)
given_config_source.file = git_pathdup("config.worktree");
else if (worktrees[0] && worktrees[1]) {
- die("BUG: migration is not supported yet");
+ migrate_worktree_config();
+ given_config_source.file = git_pathdup("config.worktree");
} else
given_config_source.file = git_pathdup("config");
free_worktrees(worktrees);
diff --git a/worktree.c b/worktree.c
index eb61212..d8c9d85 100644
--- a/worktree.c
+++ b/worktree.c
@@ -380,3 +380,43 @@ const struct worktree *find_shared_symref(const char *symref,
return existing;
}
+
+void migrate_worktree_config(void)
+{
+ struct strbuf worktree_path = STRBUF_INIT;
+ struct strbuf main_path = STRBUF_INIT;
+ struct repository_format format;
+
+ assert(repository_format_worktree_config == 0);
+
+ strbuf_git_common_path(&worktree_path, "config.worktree");
+ strbuf_git_path(&main_path, "config");
+
+ read_repository_format(&format, main_path.buf);
+ assert(format.worktree_config == 0);
+
+ if (format.is_bare >= 0) {
+ git_config_set_in_file(worktree_path.buf,
+ "core.bare", "true");
+ git_config_set_in_file(main_path.buf,
+ "core.bare", NULL);
+ }
+ if (format.work_tree) {
+ git_config_set_in_file(worktree_path.buf,
+ "core.worktree",
+ format.work_tree);
+ git_config_set_in_file(main_path.buf,
+ "core.worktree", NULL);
+ }
+
+ git_config_set_in_file(main_path.buf,
+ "extensions.worktreeConfig", "true");
+ if (format.version == 0)
+ git_config_set_in_file(main_path.buf,
+ "core.repositoryFormatVersion", "1");
+
+ repository_format_worktree_config = 1;
+
+ strbuf_release(&main_path);
+ strbuf_release(&worktree_path);
+}
diff --git a/worktree.h b/worktree.h
index d59ce1f..cf82676 100644
--- a/worktree.h
+++ b/worktree.h
@@ -76,4 +76,10 @@ extern const char *worktree_git_path(const struct worktree *wt,
const char *fmt, ...)
__attribute__((format (printf, 2, 3)));
+/*
+ * Called to add extensions.worktreeConfig to $GIT_DIR/config and move
+ * main worktree specific config variables to $GIT_DIR/config.worktree.
+ */
+extern void migrate_worktree_config(void);
+
#endif
--
2.8.2.524.g6ff3d78
next prev parent reply other threads:[~2017-01-10 11:27 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-01-10 11:25 [PATCH v5 0/4] Per-worktree config file support Nguyễn Thái Ngọc Duy
2017-01-10 11:25 ` [PATCH v5 1/4] config: read per-worktree config files Nguyễn Thái Ngọc Duy
2017-01-10 11:25 ` [PATCH v5 2/4] config: --worktree for manipulating per-worktree config file Nguyễn Thái Ngọc Duy
2017-01-10 16:52 ` Stefan Beller
2017-01-10 11:25 ` Nguyễn Thái Ngọc Duy [this message]
2017-01-10 11:25 ` [PATCH v5 4/4] t2029: add tests for per-worktree config Nguyễn Thái Ngọc Duy
2017-01-10 11:33 ` [PATCH/RFC 5/4] Redefine core.bare in multiple working tree setting Nguyễn Thái Ngọc Duy
2017-01-12 23:08 ` Junio C Hamano
2017-01-19 12:02 ` Duy Nguyen
2017-01-10 11:41 ` [PATCH v5 0/4] Per-worktree config file support Duy Nguyen
2017-01-10 17:01 ` Stefan Beller
2017-01-19 12:09 ` Duy Nguyen
2017-01-19 20:03 ` Stefan Beller
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: http://vger.kernel.org/majordomo-info.html
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20170110112524.12870-4-pclouds@gmail.com \
--to=pclouds@gmail.com \
--cc=Jens.Lehmann@web.de \
--cc=git@drmicha.warpmail.net \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=larsxschneider@gmail.com \
--cc=max@max630.net \
--cc=mhagger@alum.mit.edu \
--cc=sbeller@google.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://80x24.org/mirrors/git.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).