-
Notifications
You must be signed in to change notification settings - Fork 127
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Sparse checkout: fix bug with worktree of bare repo #1101
Changes from 5 commits
0260ff6
5d0cc24
cf9e86f
5b5924e
c51cb37
f687a0b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,3 +6,34 @@ extensions.objectFormat:: | |
Note that this setting should only be set by linkgit:git-init[1] or | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On the Git mailing list, Elijah Newren wrote (reply to this):
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On the Git mailing list, Derrick Stolee wrote (reply to this):
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On the Git mailing list, Eric Sunshine wrote (reply to this):
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On the Git mailing list, Junio C Hamano wrote (reply to this):
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On the Git mailing list, Derrick Stolee wrote (reply to this):
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On the Git mailing list, Junio C Hamano wrote (reply to this):
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On the Git mailing list, Derrick Stolee wrote (reply to this):
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On the Git mailing list, Elijah Newren wrote (reply to this):
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On the Git mailing list, Elijah Newren wrote (reply to this):
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On the Git mailing list, Junio C Hamano wrote (reply to this):
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On the Git mailing list, Junio C Hamano wrote (reply to this):
|
||
linkgit:git-clone[1]. Trying to change it after initialization will not | ||
work and will produce hard-to-diagnose issues. | ||
|
||
extensions.worktreeConfig:: | ||
If enabled, then worktrees will load config settings from the | ||
`$GIT_DIR/config.worktree` file in addition to the | ||
`$GIT_COMMON_DIR/config` file. Note that `$GIT_COMMON_DIR` and | ||
`$GIT_DIR` are the same for the main working tree, while other | ||
working trees have `$GIT_DIR` equal to | ||
`$GIT_COMMON_DIR/worktrees/<id>/`. The settings in the | ||
`config.worktree` file will override settings from any other | ||
config files. | ||
+ | ||
When enabling `extensions.worktreeConfig`, you must be careful to move | ||
certain values from the common config file to the main working tree's | ||
`config.worktree` file, if present: | ||
+ | ||
* `core.worktree` must be moved from `$GIT_COMMON_DIR/config` to | ||
`$GIT_COMMON_DIR/config.worktree`. | ||
* If `core.bare` is true, then it must be moved from `$GIT_COMMON_DIR/config` | ||
to `$GIT_COMMON_DIR/config.worktree`. | ||
+ | ||
It may also be beneficial to adjust the locations of `core.sparseCheckout` | ||
and `core.sparseCheckoutCone` depending on your desire for customizable | ||
sparse-checkout settings for each worktree. By default, the `git | ||
sparse-checkout` builtin enables `extensions.worktreeConfig`, assigns | ||
these config values on a per-worktree basis, and uses the | ||
`$GIT_DIR/info/sparse-checkout` file to specify the sparsity for each | ||
worktree independently. See linkgit:git-sparse-checkout[1] for more | ||
details. | ||
+ | ||
For historical reasons, `extensions.worktreeConfig` is respected | ||
regardless of the `core.repositoryFormatVersion` setting. |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,13 +31,21 @@ COMMANDS | |
Describe the patterns in the sparse-checkout file. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On the Git mailing list, Elijah Newren wrote (reply to this):
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On the Git mailing list, Derrick Stolee wrote (reply to this):
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On the Git mailing list, Eric Sunshine wrote (reply to this):
|
||
|
||
'set':: | ||
Enable the necessary config settings | ||
(extensions.worktreeConfig, core.sparseCheckout, | ||
core.sparseCheckoutCone) if they are not already enabled, and | ||
write a set of patterns to the sparse-checkout file from the | ||
Enable the necessary sparse-checkout config settings | ||
(`core.sparseCheckout`, `core.sparseCheckoutCone`, and | ||
`index.sparse`) if they are not already set to the desired values, | ||
and write a set of patterns to the sparse-checkout file from the | ||
list of arguments following the 'set' subcommand. Update the | ||
working directory to match the new patterns. | ||
+ | ||
To ensure that adjusting the sparse-checkout settings within a worktree | ||
does not alter the sparse-checkout settings in other worktrees, the 'set' | ||
subcommand will upgrade your repository config to use worktree-specific | ||
config if not already present. The sparsity defined by the arguments to | ||
the 'set' subcommand are stored in the worktree-specific sparse-checkout | ||
file. See linkgit:git-worktree[1] and the documentation of | ||
`extensions.worktreeConfig` in linkgit:git-config[1] for more details. | ||
+ | ||
When the `--stdin` option is provided, the patterns are read from | ||
standard in as a newline-delimited list instead of from the arguments. | ||
+ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,7 @@ | |
#include "wt-status.h" | ||
#include "quote.h" | ||
#include "sparse-index.h" | ||
#include "worktree.h" | ||
|
||
static const char *empty_base = ""; | ||
|
||
|
@@ -359,26 +360,23 @@ enum sparse_checkout_mode { | |
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On the Git mailing list, Eric Sunshine wrote (reply to this):
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On the Git mailing list, Eric Sunshine wrote (reply to this):
|
||
static int set_config(enum sparse_checkout_mode mode) | ||
{ | ||
const char *config_path; | ||
|
||
if (upgrade_repository_format(1) < 0) | ||
die(_("unable to upgrade repository format to enable worktreeConfig")); | ||
if (git_config_set_gently("extensions.worktreeConfig", "true")) { | ||
error(_("failed to set extensions.worktreeConfig setting")); | ||
/* Update to use worktree config, if not already. */ | ||
if (init_worktree_config(the_repository)) { | ||
error(_("failed to initialize worktree config")); | ||
return 1; | ||
} | ||
|
||
config_path = git_path("config.worktree"); | ||
git_config_set_in_file_gently(config_path, | ||
"core.sparseCheckout", | ||
mode ? "true" : NULL); | ||
|
||
git_config_set_in_file_gently(config_path, | ||
"core.sparseCheckoutCone", | ||
mode == MODE_CONE_PATTERNS ? "true" : NULL); | ||
if (repo_config_set_worktree_gently(the_repository, | ||
"core.sparseCheckout", | ||
mode ? "true" : "false") || | ||
repo_config_set_worktree_gently(the_repository, | ||
"core.sparseCheckoutCone", | ||
mode == MODE_CONE_PATTERNS ? | ||
"true" : "false")) | ||
return 1; | ||
|
||
if (mode == MODE_NO_PATTERNS) | ||
set_sparse_index_config(the_repository, 0); | ||
return set_sparse_index_config(the_repository, 0); | ||
|
||
return 0; | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -335,6 +335,69 @@ static int add_worktree(const char *path, const char *refname, | |
strbuf_addf(&sb, "%s/commondir", sb_repo.buf); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On the Git mailing list, Elijah Newren wrote (reply to this):
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On the Git mailing list, Jean-Noël AVILA wrote (reply to this):
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On the Git mailing list, Derrick Stolee wrote (reply to this):
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On the Git mailing list, Jean-Noël Avila wrote (reply to this):
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On the Git mailing list, Derrick Stolee wrote (reply to this):
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On the Git mailing list, Eric Sunshine wrote (reply to this):
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On the Git mailing list, Eric Sunshine wrote (reply to this):
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On the Git mailing list, Derrick Stolee wrote (reply to this):
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On the Git mailing list, Eric Sunshine wrote (reply to this):
|
||
write_file(sb.buf, "../.."); | ||
|
||
/* | ||
* 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 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); | ||
} | ||
|
||
strvec_pushf(&child_env, "%s=%s", GIT_DIR_ENVIRONMENT, sb_git.buf); | ||
strvec_pushf(&child_env, "%s=%s", GIT_WORK_TREE_ENVIRONMENT, path); | ||
cp.git_cmd = 1; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,6 +21,7 @@ | |
#include "dir.h" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On the Git mailing list, Eric Sunshine wrote (reply to this):
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On the Git mailing list, Junio C Hamano wrote (reply to this):
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On the Git mailing list, Derrick Stolee wrote (reply to this):
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On the Git mailing list, Junio C Hamano wrote (reply to this):
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On the Git mailing list, Derrick Stolee wrote (reply to this):
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On the Git mailing list, Junio C Hamano wrote (reply to this):
|
||
#include "color.h" | ||
#include "refs.h" | ||
#include "worktree.h" | ||
|
||
struct config_source { | ||
struct config_source *prev; | ||
|
@@ -2884,6 +2885,20 @@ int git_config_set_gently(const char *key, const char *value) | |
return git_config_set_multivar_gently(key, value, NULL, 0); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On the Git mailing list, Derrick Stolee wrote (reply to this):
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On the Git mailing list, Eric Sunshine wrote (reply to this):
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On the Git mailing list, Eric Sunshine wrote (reply to this):
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On the Git mailing list, Derrick Stolee wrote (reply to this):
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On the Git mailing list, Eric Sunshine wrote (reply to this):
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On the Git mailing list, Derrick Stolee wrote (reply to this):
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On the Git mailing list, Eric Sunshine wrote (reply to this):
|
||
} | ||
|
||
int repo_config_set_worktree_gently(struct repository *r, | ||
const char *key, const char *value) | ||
{ | ||
/* Only use worktree-specific config if it is is already enabled. */ | ||
if (repository_format_worktree_config) { | ||
char *file = repo_git_path(r, "config.worktree"); | ||
int ret = git_config_set_multivar_in_file_gently( | ||
file, key, value, NULL, 0); | ||
free(file); | ||
return ret; | ||
} | ||
return repo_config_set_multivar_gently(r, key, value, NULL, 0); | ||
} | ||
|
||
void git_config_set(const char *key, const char *value) | ||
{ | ||
git_config_set_multivar(key, value, NULL, 0); | ||
|
@@ -3181,14 +3196,28 @@ void git_config_set_multivar_in_file(const char *config_filename, | |
int git_config_set_multivar_gently(const char *key, const char *value, | ||
const char *value_pattern, unsigned flags) | ||
{ | ||
return git_config_set_multivar_in_file_gently(NULL, key, value, value_pattern, | ||
flags); | ||
return repo_config_set_multivar_gently(the_repository, key, value, | ||
value_pattern, flags); | ||
} | ||
|
||
int repo_config_set_multivar_gently(struct repository *r, const char *key, | ||
const char *value, | ||
const char *value_pattern, unsigned flags) | ||
{ | ||
char *file = repo_git_path(r, "config"); | ||
int res = git_config_set_multivar_in_file_gently(file, | ||
key, value, | ||
value_pattern, | ||
flags); | ||
free(file); | ||
return res; | ||
} | ||
|
||
void git_config_set_multivar(const char *key, const char *value, | ||
const char *value_pattern, unsigned flags) | ||
{ | ||
git_config_set_multivar_in_file(NULL, key, value, value_pattern, | ||
git_config_set_multivar_in_file(git_path("config"), | ||
key, value, value_pattern, | ||
flags); | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On the Git mailing list, Bagas Sanjaya wrote (reply to this):
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On the Git mailing list, Derrick Stolee wrote (reply to this):