Skip to content

Commit 1860ba1

Browse files
calebdwgitster
authored andcommitted
worktree: add relativeWorktrees extension
A new extension, `relativeWorktrees`, is added to indicate that at least one worktree in the repository has been linked with relative paths. This ensures older Git versions do not attempt to automatically prune worktrees with relative paths, as they would not not recognize the paths as being valid. Suggested-by: Junio C Hamano <[email protected]> Signed-off-by: Caleb White <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent d897f2c commit 1860ba1

File tree

5 files changed

+16
-0
lines changed

5 files changed

+16
-0
lines changed

Documentation/config/extensions.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,12 @@ Note that this setting should only be set by linkgit:git-init[1] or
6363
linkgit:git-clone[1]. Trying to change it after initialization will not
6464
work and will produce hard-to-diagnose issues.
6565

66+
relativeWorktrees::
67+
If enabled, indicates at least one worktree has been linked with
68+
relative paths. Automatically set if a worktree has been created or
69+
repaired with either the `--relative-paths` option or with the
70+
`worktree.useRelativePaths` config set to `true`.
71+
6672
worktreeConfig::
6773
If enabled, then worktrees will load config settings from the
6874
`$GIT_DIR/config.worktree` file in addition to the

repository.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,7 @@ int repo_init(struct repository *repo,
283283
repo_set_compat_hash_algo(repo, format.compat_hash_algo);
284284
repo_set_ref_storage_format(repo, format.ref_storage_format);
285285
repo->repository_format_worktree_config = format.worktree_config;
286+
repo->repository_format_relative_worktrees = format.relative_worktrees;
286287

287288
/* take ownership of format.partial_clone */
288289
repo->repository_format_partial_clone = format.partial_clone;

repository.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@ struct repository {
150150

151151
/* Configurations */
152152
int repository_format_worktree_config;
153+
int repository_format_relative_worktrees;
153154

154155
/* Indicate if a repository has a different 'commondir' from 'gitdir' */
155156
unsigned different_commondir:1;

setup.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -683,6 +683,9 @@ static enum extension_result handle_extension(const char *var,
683683
"extensions.refstorage", value);
684684
data->ref_storage_format = format;
685685
return EXTENSION_OK;
686+
} else if (!strcmp(ext, "relativeworktrees")) {
687+
data->relative_worktrees = git_config_bool(var, value);
688+
return EXTENSION_OK;
686689
}
687690
return EXTENSION_UNKNOWN;
688691
}
@@ -1854,6 +1857,8 @@ const char *setup_git_directory_gently(int *nongit_ok)
18541857
repo_fmt.ref_storage_format);
18551858
the_repository->repository_format_worktree_config =
18561859
repo_fmt.worktree_config;
1860+
the_repository->repository_format_relative_worktrees =
1861+
repo_fmt.relative_worktrees;
18571862
/* take ownership of repo_fmt.partial_clone */
18581863
the_repository->repository_format_partial_clone =
18591864
repo_fmt.partial_clone;
@@ -1950,6 +1955,8 @@ void check_repository_format(struct repository_format *fmt)
19501955
fmt->ref_storage_format);
19511956
the_repository->repository_format_worktree_config =
19521957
fmt->worktree_config;
1958+
the_repository->repository_format_relative_worktrees =
1959+
fmt->relative_worktrees;
19531960
the_repository->repository_format_partial_clone =
19541961
xstrdup_or_null(fmt->partial_clone);
19551962
clear_repository_format(&repo_fmt);

setup.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ struct repository_format {
129129
int precious_objects;
130130
char *partial_clone; /* value of extensions.partialclone */
131131
int worktree_config;
132+
int relative_worktrees;
132133
int is_bare;
133134
int hash_algo;
134135
int compat_hash_algo;

0 commit comments

Comments
 (0)