Skip to contentSkip to conversation

setup_git_directory(): fix move to worktree toplevel directory

PATCH New Nguyễn Thái Ngọc Duy 1 participant 1 message Jun 15, 2016

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 setup_git_directory(): fix move to worktree toplevel directory

When setup_git_directory() returns successfully, it is supposed to move current working directory to worktree toplevel directory.

However, the code recomputing prefix inside setup_git_directory() has to move cwd back to original working directory, in order to get new prefix. After that, it should move cwd back to worktree toplevel directory as expected.

---
This is a revised version of "Preserve cwd in setup_git_directory()" I sent before. Hopefully this time the commit message makes it clear.

 setup.c |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)
setup.c +2 -0
index 6cf9094..2e3248a 100644
@@ -581,6 +581,8 @@ const char *setup_git_directory(void)
 		if (retval && chdir(retval))
 			die ("Could not jump back into original cwd");
 		rel = get_relative_cwd(buffer, PATH_MAX, get_git_work_tree());
+		if (rel && *rel && chdir(get_git_work_tree()))
+			die ("Could not jump to working directory");
 		return rel && *rel ? strcat(rel, "/") : NULL;
 	}
 
Signature · 1 line
1.6.0.96.g2fad1.dirty