Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.kernel.org/pub/scm/git/git.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEric Sunshine <sunshine@sunshineco.com>2020-08-01 02:32:13 +0300
committerJunio C Hamano <gitster@pobox.com>2020-08-01 05:56:11 +0300
commit1c4854ec7333f412cd60a5b673bb4f4e43319391 (patch)
treee6f790dddf00209bd8593b500139d9779c16bcd4 /worktree.c
parent246756f775bdd3055da969a16d9e9c74e76a3e06 (diff)
worktree: drop bogus and unnecessary path munging
The content of .git/worktrees/<id>/gitdir must be a path of the form "/path/to/worktree/.git". Any other content would be indicative of a corrupt "gitdir" file. To determine the path of the worktree itself one merely strips the "/.git" suffix, and this is indeed how the worktree path was determined from inception. However, 5193490442 (worktree: add a function to get worktree details, 2015-10-08) extended the path manipulation in a mysterious way. If it is unable to strip "/.git" from the path, then it instead reports the current working directory as the linked worktree's path: if (!strbuf_strip_suffix(&worktree_path, "/.git")) { strbuf_reset(&worktree_path); strbuf_add_absolute_path(&worktree_path, "."); strbuf_strip_suffix(&worktree_path, "/."); } This logic is clearly bogus; it can never be generally correct behavior. It materialized out of thin air in 5193490442 with neither explanation nor tests to illustrate a case in which it would be desirable. It's possible that this logic was introduced to somehow deal with a corrupt "gitdir" file, so that it returns _some_ sort of meaningful value, but returning the current working directory is not helpful. In fact, it is quite misleading (except in the one specific case when the current directory is the worktree whose "gitdir" entry is corrupt). Moreover, reporting the corrupt value to the user, rather than fibbing about it and hiding it outright, is more helpful since it may aid in diagnosing the problem. Therefore, drop this bogus path munging and restore the logic to the original behavior of merely stripping "/.git". Signed-off-by: Eric Sunshine <sunshine@sunshineco.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'worktree.c')
-rw-r--r--worktree.c7
1 files changed, 1 insertions, 6 deletions
diff --git a/worktree.c b/worktree.c
index fa8366a3ca..355824bf87 100644
--- a/worktree.c
+++ b/worktree.c
@@ -82,13 +82,8 @@ static struct worktree *get_linked_worktree(const char *id)
if (strbuf_read_file(&worktree_path, path.buf, 0) <= 0)
/* invalid gitdir file */
goto done;
-
strbuf_rtrim(&worktree_path);
- if (!strbuf_strip_suffix(&worktree_path, "/.git")) {
- strbuf_reset(&worktree_path);
- strbuf_add_absolute_path(&worktree_path, ".");
- strbuf_strip_suffix(&worktree_path, "/.");
- }
+ strbuf_strip_suffix(&worktree_path, "/.git");
worktree = xcalloc(1, sizeof(*worktree));
worktree->path = strbuf_detach(&worktree_path, NULL);