Thread (45 messages) flat view 45 messages, 2 authors, 2016-06-15
DORMANTno replies

Revision v1 of 2 in this series.

Revisions (2)
  1. v1 [diff vs current]
  2. v1 current

[PATCH 6/7] get_git_work_tree: core.worktree relative to git_dir

From: Nguyễn Thái Ngọc Duy <hidden>
Date: 2016-06-15 22:49:55
Subsystem: the rest · Maintainer: Linus Torvalds

---
 environment.c |   12 ++++++++++--
 1 files changed, 10 insertions(+), 2 deletions(-)
diff --git a/environment.c b/environment.c
index de5581f..d41dcfb 100644
--- a/environment.c
+++ b/environment.c
@@ -153,8 +153,16 @@ const char *get_git_work_tree(void)
 		if (!work_tree && is_bare_repository_cfg < 1) {
 			work_tree = git_work_tree_cfg;
 			/* make_absolute_path also normalizes the path */
-			if (work_tree && !is_absolute_path(work_tree))
-				work_tree = xstrdup(make_absolute_path(git_path("%s", work_tree)));
+			if (work_tree && !is_absolute_path(work_tree)) {
+				char cwd[PATH_MAX];
+				if (!getcwd(cwd, PATH_MAX))
+					die("Could not get current working directory");
+				if (chdir(get_git_dir()))
+					die("Could not chdir to $GIT_DIR");
+				work_tree = xstrdup(make_absolute_path(work_tree));
+				if (chdir(cwd))
+					die("Could not chdir to previous working directory");
+			}
 		} else if (work_tree)
 			work_tree = xstrdup(make_absolute_path(work_tree));
 		git_work_tree_initialized = 1;
-- 
1.7.0.2.445.gcbdb3
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help