}
if (!sb->contents_from)
- setup_work_tree();
+ setup_work_tree(the_repository);
sb->final = fake_working_tree_commit(sb->repo,
&sb->revs->diffopt,
int cnt, i, doubledash, filei;
if (!is_bare_repository())
- setup_work_tree();
+ setup_work_tree(the_repository);
repo_config(the_repository, git_default_config, NULL);
}
/* We need to be in the new work tree for the checkout */
- setup_work_tree();
+ setup_work_tree(the_repository);
repo_hold_locked_index(the_repository, &lock_file, LOCK_DIE_ON_ERROR);
struct rev_info revs;
int fd;
- setup_work_tree();
+ setup_work_tree(the_repository);
prepare_repo_settings(the_repository);
the_repository->settings.command_requires_full_index = 0;
repo_read_index(the_repository);
rev.max_count != -1 || rev.min_age != -1 || rev.max_age != -1)
usage(diff_cache_usage);
if (!(option & DIFF_INDEX_CACHED)) {
- setup_work_tree();
+ setup_work_tree(the_repository);
if (repo_read_index_preload(the_repository, &rev.diffopt.pathspec, 0) < 0) {
perror("repo_read_index_preload");
return -1;
revs->max_age != -1)
usage(builtin_diff_usage);
if (!(option & DIFF_INDEX_CACHED)) {
- setup_work_tree();
+ setup_work_tree(the_repository);
if (repo_read_index_preload(the_repository,
&revs->diffopt.pathspec, 0) < 0) {
die_errno("repo_read_index_preload");
(revs->diffopt.output_format & DIFF_FORMAT_PATCH))
diff_merges_set_dense_combined_if_unset(revs);
- setup_work_tree();
+ setup_work_tree(the_repository);
if (repo_read_index_preload(the_repository, &revs->diffopt.pathspec,
0) < 0) {
die_errno("repo_read_index_preload");
die(_("difftool requires worktree or --no-index"));
if (!no_index){
- setup_work_tree();
+ setup_work_tree(repo);
setenv(GIT_DIR_ENVIRONMENT, absolute_path(repo_get_git_dir(repo)), 1);
setenv(GIT_WORK_TREE_ENVIRONMENT, absolute_path(repo_get_work_tree(repo)), 1);
} else if (dir_diff)
die(_("--[no-]exclude-standard cannot be used for tracked contents"));
} else if (!list.nr) {
if (!cached)
- setup_work_tree();
+ setup_work_tree(the_repository);
hit = grep_cache(&opt, &pathspec, cached);
} else {
exc_given = 1;
if (require_work_tree && !is_inside_work_tree(repo))
- setup_work_tree();
+ setup_work_tree(repo);
if (recurse_submodules &&
(show_deleted || show_others || show_unmerged ||
opts.preserve_ignored = 0;
/* otherwise, opts.preserve_ignored is irrelevant */
if (opts.merge && !opts.index_only)
- setup_work_tree();
+ setup_work_tree(the_repository);
if (opts.skip_sparse_checkout)
ensure_full_index(the_repository->index);
trace2_cmd_mode(reset_type_names[reset_type]);
if (reset_type != SOFT && (reset_type != MIXED || repo_get_work_tree(the_repository)))
- setup_work_tree();
+ setup_work_tree(the_repository);
if (reset_type == MIXED && is_bare_repository())
die(_("%s reset is not allowed in a bare repository"),
die(_("No pathspec was given. Which files should I remove?"));
if (!index_only)
- setup_work_tree();
+ setup_work_tree(the_repository);
prepare_repo_settings(the_repository);
the_repository->settings.command_requires_full_index = 0;
int res;
struct repo_config_values *cfg = repo_config_values(the_repository);
- setup_work_tree();
+ setup_work_tree(the_repository);
if (!cfg->apply_sparse_checkout)
die(_("this worktree is not sparse"));
o.dst_index = r->index;
o.skip_sparse_checkout = 0;
- setup_work_tree();
+ setup_work_tree(the_repository);
repo_hold_locked_index(r, &lock_file, LOCK_DIE_ON_ERROR);
OPT_END(),
};
- setup_work_tree();
+ setup_work_tree(the_repository);
repo_read_index(repo);
init_opts.cone_mode = -1;
int ret;
struct repo_config_values *cfg = repo_config_values(the_repository);
- setup_work_tree();
+ setup_work_tree(the_repository);
if (!cfg->apply_sparse_checkout)
die(_("no sparse-checkout to add to"));
struct strvec patterns = STRVEC_INIT;
int ret;
- setup_work_tree();
+ setup_work_tree(the_repository);
repo_read_index(repo);
set_opts.cone_mode = -1;
};
struct repo_config_values *cfg = repo_config_values(the_repository);
- setup_work_tree();
+ setup_work_tree(the_repository);
if (!cfg->apply_sparse_checkout)
die(_("must be in a sparse-checkout to reapply sparsity patterns"));
OPT_END(),
};
- setup_work_tree();
+ setup_work_tree(the_repository);
if (!cfg->apply_sparse_checkout)
die(_("must be in a sparse-checkout to clean directories"));
if (!core_sparse_checkout_cone)
* forcibly return to a dense checkout regardless of initial state.
*/
- setup_work_tree();
+ setup_work_tree(the_repository);
argc = parse_options(argc, argv, prefix,
builtin_sparse_checkout_disable_options,
builtin_sparse_checkout_disable_usage, 0);
if (!info->cached) {
if (diff_cmd == DIFF_INDEX)
- setup_work_tree();
+ setup_work_tree(the_repository);
if (repo_read_index_preload(the_repository, &rev.diffopt.pathspec, 0) < 0) {
perror("repo_read_index_preload");
ret = -1;
static int refresh(struct refresh_params *o, unsigned int flag)
{
- setup_work_tree();
+ setup_work_tree(the_repository);
repo_read_index(the_repository);
*o->has_errors |= refresh_index(the_repository->index, o->flags | flag, NULL,
NULL, NULL);
BUG_ON_OPT_ARG(arg);
/* consume remaining arguments. */
- setup_work_tree();
+ setup_work_tree(the_repository);
*has_errors = do_reupdate(ctx->argv + 1, prefix);
if (*has_errors)
the_repository->index->cache_changed = 0;
transaction = NULL;
}
- setup_work_tree();
+ setup_work_tree(the_repository);
p = prefix_path(the_repository, prefix, prefix_length, path);
update_one(p);
if (set_executable_bit)
struct strbuf buf = STRBUF_INIT;
struct strbuf unquoted = STRBUF_INIT;
- setup_work_tree();
+ setup_work_tree(the_repository);
while (getline_fn(&buf, stdin) != EOF) {
char *p;
if (!nul_term_line && buf.buf[0] == '"') {
report(_("Untracked cache disabled"));
break;
case UC_TEST:
- setup_work_tree();
+ setup_work_tree(the_repository);
return !test_if_untracked_cache_is_supported();
case UC_ENABLE:
case UC_FORCE:
commit_pager_choice();
if (!help && p->option & NEED_WORK_TREE)
- setup_work_tree();
+ setup_work_tree(the_repository);
trace_argv_printf(argv, "trace: built-in: git");
trace2_cmd_name(p->cmd);
* A NULL value indicates that there is no working directory.
*/
char *worktree;
+ bool worktree_config_is_bogus;
/*
* Path from the root of the top-level superproject down to this
#include "trace2.h"
#include "worktree.h"
-static int work_tree_config_is_bogus;
enum allowed_bare_repo {
ALLOWED_BARE_REPO_EXPLICIT = 0,
ALLOWED_BARE_REPO_ALL,
return ret;
}
-void setup_work_tree(void)
+void setup_work_tree(struct repository *repo)
{
const char *work_tree;
- static int initialized = 0;
- if (initialized)
- return;
-
- if (work_tree_config_is_bogus)
+ if (repo->worktree_config_is_bogus)
die(_("unable to set up work tree using invalid config"));
- work_tree = repo_get_work_tree(the_repository);
+ work_tree = repo_get_work_tree(repo);
if (!work_tree || chdir_notify(work_tree))
die(_("this operation must be run in a work tree"));
*/
if (getenv(GIT_WORK_TREE_ENVIRONMENT))
setenv(GIT_WORK_TREE_ENVIRONMENT, ".", 1);
-
- initialized = 1;
}
static void setup_original_cwd(struct repository *repo)
if (git_work_tree_cfg) {
/* #22.2, #30 */
warning("core.bare and core.worktree do not make sense");
- work_tree_config_is_bogus = 1;
+ repo->worktree_config_is_bogus = true;
}
/* #18, #26 */
void die_upon_dubious_ownership(const char *gitfile, const char *worktree,
const char *gitdir);
-void setup_work_tree(void);
+void setup_work_tree(struct repository *repo);
/*
* discover_git_directory_reason() is similar to discover_git_directory(),
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "test-tool.h"
#include "run-command.h"
#include "setup.h"
if (nogit)
die("No git repo found");
if (argc > 1 && !strcmp(argv[1], "--setup-work-tree")) {
- setup_work_tree();
+ setup_work_tree(the_repository);
argv++;
}
cp.git_cmd = 1;
status_printf_ln(s, c,
"--------------------------------------------------");
status_printf_ln(s, c, _("Changes not staged for commit:"));
- setup_work_tree();
+ setup_work_tree(the_repository);
rev.diffopt.a_prefix = "i/";
rev.diffopt.b_prefix = "w/";
run_diff_files(&rev, 0);