Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.kernel.org/pub/scm/git/git.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2022-03-07 08:25:31 +0300
committerJunio C Hamano <gitster@pobox.com>2022-03-07 08:25:31 +0300
commitaae90a156de9d84cfe5e2052678d22c18ff285b2 (patch)
tree4eb198e5ef5043fa682cb7d4af2d0fcd544c49c0 /builtin/worktree.c
parent50e0dd8fee3828adafc27fc7c0a5262137577ddf (diff)
parent07d85380b21653b949f2777903e44aaf0fdb6c44 (diff)
Merge branch 'ds/worktree-docs'
Tighten the language around "working tree" and "worktree" in the docs. * ds/worktree-docs: worktree: use 'worktree' over 'working tree' worktree: use 'worktree' over 'working tree' worktree: use 'worktree' over 'working tree' worktree: use 'worktree' over 'working tree' worktree: use 'worktree' over 'working tree' worktree: use 'worktree' over 'working tree' worktree: use 'worktree' over 'working tree' worktree: extract checkout_worktree() worktree: extract copy_sparse_checkout() worktree: extract copy_filtered_worktree_config() worktree: combine two translatable messages
Diffstat (limited to 'builtin/worktree.c')
-rw-r--r--builtin/worktree.c138
1 files changed, 75 insertions, 63 deletions
diff --git a/builtin/worktree.c b/builtin/worktree.c
index e23e6343d0..4eaba2a8fd 100644
--- a/builtin/worktree.c
+++ b/builtin/worktree.c
@@ -236,6 +236,74 @@ static void check_candidate_path(const char *path,
die(_("'%s' is a missing but already registered worktree;\nuse '%s -f' to override, or 'prune' or 'remove' to clear"), path, cmd);
}
+static void copy_sparse_checkout(const char *worktree_git_dir)
+{
+ char *from_file = git_pathdup("info/sparse-checkout");
+ char *to_file = xstrfmt("%s/info/sparse-checkout", worktree_git_dir);
+
+ if (file_exists(from_file)) {
+ if (safe_create_leading_directories(to_file) ||
+ copy_file(to_file, from_file, 0666))
+ error(_("failed to copy '%s' to '%s'; sparse-checkout may not work correctly"),
+ from_file, to_file);
+ }
+
+ free(from_file);
+ free(to_file);
+}
+
+static void copy_filtered_worktree_config(const char *worktree_git_dir)
+{
+ char *from_file = git_pathdup("config.worktree");
+ char *to_file = xstrfmt("%s/config.worktree", worktree_git_dir);
+
+ if (file_exists(from_file)) {
+ struct config_set cs = { { 0 } };
+ const char *core_worktree;
+ int bare;
+
+ if (safe_create_leading_directories(to_file) ||
+ copy_file(to_file, from_file, 0666)) {
+ error(_("failed to copy worktree config from '%s' to '%s'"),
+ from_file, to_file);
+ goto worktree_copy_cleanup;
+ }
+
+ git_configset_init(&cs);
+ git_configset_add_file(&cs, from_file);
+
+ if (!git_configset_get_bool(&cs, "core.bare", &bare) &&
+ bare &&
+ git_config_set_multivar_in_file_gently(
+ to_file, "core.bare", NULL, "true", 0))
+ error(_("failed to unset '%s' in '%s'"),
+ "core.bare", to_file);
+ if (!git_configset_get_value(&cs, "core.worktree", &core_worktree) &&
+ git_config_set_in_file_gently(to_file,
+ "core.worktree", NULL))
+ error(_("failed to unset '%s' in '%s'"),
+ "core.worktree", to_file);
+
+ git_configset_clear(&cs);
+ }
+
+worktree_copy_cleanup:
+ free(from_file);
+ free(to_file);
+}
+
+static int checkout_worktree(const struct add_opts *opts,
+ struct strvec *child_env)
+{
+ struct child_process cp = CHILD_PROCESS_INIT;
+ cp.git_cmd = 1;
+ strvec_pushl(&cp.args, "reset", "--hard", "--no-recurse-submodules", NULL);
+ if (opts->quiet)
+ strvec_push(&cp.args, "--quiet");
+ strvec_pushv(&cp.env_array, child_env->v);
+ return run_command(&cp);
+}
+
static int add_worktree(const char *path, const char *refname,
const struct add_opts *opts)
{
@@ -339,64 +407,16 @@ static int add_worktree(const char *path, const char *refname,
* If the current worktree has sparse-checkout enabled, then copy
* the sparse-checkout patterns from the current worktree.
*/
- if (core_apply_sparse_checkout) {
- char *from_file = git_pathdup("info/sparse-checkout");
- char *to_file = xstrfmt("%s/info/sparse-checkout",
- sb_repo.buf);
-
- if (file_exists(from_file)) {
- if (safe_create_leading_directories(to_file) ||
- copy_file(to_file, from_file, 0666))
- error(_("failed to copy '%s' to '%s'; sparse-checkout may not work correctly"),
- from_file, to_file);
- }
-
- free(from_file);
- free(to_file);
- }
+ if (core_apply_sparse_checkout)
+ copy_sparse_checkout(sb_repo.buf);
/*
* If we are using worktree config, then copy all current config
* values from the current worktree into the new one, that way the
* new worktree behaves the same as this one.
*/
- if (repository_format_worktree_config) {
- char *from_file = git_pathdup("config.worktree");
- char *to_file = xstrfmt("%s/config.worktree",
- sb_repo.buf);
-
- if (file_exists(from_file)) {
- struct config_set cs = { { 0 } };
- const char *core_worktree;
- int bare;
-
- if (safe_create_leading_directories(to_file) ||
- copy_file(to_file, from_file, 0666)) {
- error(_("failed to copy worktree config from '%s' to '%s'"),
- from_file, to_file);
- goto worktree_copy_cleanup;
- }
-
- git_configset_init(&cs);
- git_configset_add_file(&cs, from_file);
-
- if (!git_configset_get_bool(&cs, "core.bare", &bare) &&
- bare &&
- git_config_set_multivar_in_file_gently(
- to_file, "core.bare", NULL, "true", 0))
- error(_("failed to unset 'core.bare' in '%s'"), to_file);
- if (!git_configset_get_value(&cs, "core.worktree", &core_worktree) &&
- git_config_set_in_file_gently(to_file,
- "core.worktree", NULL))
- error(_("failed to unset 'core.worktree' in '%s'"), to_file);
-
- git_configset_clear(&cs);
- }
-
-worktree_copy_cleanup:
- free(from_file);
- free(to_file);
- }
+ if (repository_format_worktree_config)
+ copy_filtered_worktree_config(sb_repo.buf);
strvec_pushf(&child_env, "%s=%s", GIT_DIR_ENVIRONMENT, sb_git.buf);
strvec_pushf(&child_env, "%s=%s", GIT_WORK_TREE_ENVIRONMENT, path);
@@ -417,17 +437,9 @@ worktree_copy_cleanup:
if (ret)
goto done;
- if (opts->checkout) {
- struct child_process cp = CHILD_PROCESS_INIT;
- cp.git_cmd = 1;
- strvec_pushl(&cp.args, "reset", "--hard", "--no-recurse-submodules", NULL);
- if (opts->quiet)
- strvec_push(&cp.args, "--quiet");
- strvec_pushv(&cp.env_array, child_env.v);
- ret = run_command(&cp);
- if (ret)
- goto done;
- }
+ if (opts->checkout &&
+ (ret = checkout_worktree(opts, &child_env)))
+ goto done;
is_junk = 0;
FREE_AND_NULL(junk_work_tree);