aboutsummaryrefslogtreecommitdiff
path: root/environment.c
diff options
context:
space:
mode:
authorDaniel Barkalow <barkalow@iabervon.org>2008-04-27 13:39:21 -0400
committerJunio C Hamano <gitster@pobox.com>2008-05-04 17:41:44 -0700
commit19757d80e522e9f04c125ad5977c3a79db99b192 (patch)
tree56c1ac3eee61eaf56a9ad1c20cb5ad34be886377 /environment.c
parente142a3c61d22c3a3c081cb2c693e4d3725c21522 (diff)
downloadgit-19757d80e522e9f04c125ad5977c3a79db99b192.tar.gz
git-19757d80e522e9f04c125ad5977c3a79db99b192.tar.xz
Add a function to set a non-default work tree
This function may only be used before the work tree is used. Signed-off-by: Daniel Barkalow <barkalow@iabervon.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'environment.c')
-rw-r--r--environment.c24
1 files changed, 20 insertions, 4 deletions
diff --git a/environment.c b/environment.c
index 6739a3f41..0bff43204 100644
--- a/environment.c
+++ b/environment.c
@@ -41,7 +41,7 @@ enum branch_track git_branch_track = BRANCH_TRACK_REMOTE;
/* This is set by setup_git_dir_gently() and/or git_default_config() */
char *git_work_tree_cfg;
-static const char *work_tree;
+static char *work_tree;
static const char *git_dir;
static char *git_object_dir, *git_index_file, *git_refs_dir, *git_graft_file;
@@ -81,10 +81,26 @@ const char *get_git_dir(void)
return git_dir;
}
+static int git_work_tree_initialized;
+
+/*
+ * Note. This works only before you used a work tree. This was added
+ * primarily to support git-clone to work in a new repository it just
+ * created, and is not meant to flip between different work trees.
+ */
+void set_git_work_tree(const char *new_work_tree)
+{
+ if (is_bare_repository_cfg >= 0)
+ die("cannot set work tree after initialization");
+ git_work_tree_initialized = 1;
+ free(work_tree);
+ work_tree = xstrdup(make_absolute_path(new_work_tree));
+ is_bare_repository_cfg = 0;
+}
+
const char *get_git_work_tree(void)
{
- static int initialized = 0;
- if (!initialized) {
+ if (!git_work_tree_initialized) {
work_tree = getenv(GIT_WORK_TREE_ENVIRONMENT);
/* core.bare = true overrides implicit and config work tree */
if (!work_tree && is_bare_repository_cfg < 1) {
@@ -94,7 +110,7 @@ const char *get_git_work_tree(void)
work_tree = xstrdup(make_absolute_path(git_path(work_tree)));
} else if (work_tree)
work_tree = xstrdup(make_absolute_path(work_tree));
- initialized = 1;
+ git_work_tree_initialized = 1;
if (work_tree)
is_bare_repository_cfg = 0;
}