Skip to content

Commit 90c0011

Browse files
stefanbellergitster
authored andcommitted
submodule: use absolute path for computing relative path connecting
The current caller of connect_work_tree_and_git_dir passes an absolute path for the `git_dir` parameter. In the future patch we will also pass in relative path for `git_dir`. Extend the functionality of connect_work_tree_and_git_dir to take relative paths for parameters. We could work around this in the future patch by computing the absolute path for the git_dir in the calling site, however accepting relative paths for either parameter makes the API for this function much harder to misuse. Signed-off-by: Stefan Beller <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 4df1d4d commit 90c0011

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

submodule.c

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1223,27 +1223,28 @@ int merge_submodule(unsigned char result[20], const char *path,
12231223
}
12241224

12251225
/* Update gitfile and core.worktree setting to connect work tree and git dir */
1226-
void connect_work_tree_and_git_dir(const char *work_tree, const char *git_dir)
1226+
void connect_work_tree_and_git_dir(const char *work_tree_, const char *git_dir_)
12271227
{
12281228
struct strbuf file_name = STRBUF_INIT;
12291229
struct strbuf rel_path = STRBUF_INIT;
1230-
const char *real_work_tree = xstrdup(real_path(work_tree));
1230+
char *git_dir = xstrdup(real_path(git_dir_));
1231+
char *work_tree = xstrdup(real_path(work_tree_));
12311232

12321233
/* Update gitfile */
12331234
strbuf_addf(&file_name, "%s/.git", work_tree);
12341235
write_file(file_name.buf, "gitdir: %s",
1235-
relative_path(git_dir, real_work_tree, &rel_path));
1236+
relative_path(git_dir, work_tree, &rel_path));
12361237

12371238
/* Update core.worktree setting */
12381239
strbuf_reset(&file_name);
12391240
strbuf_addf(&file_name, "%s/config", git_dir);
12401241
git_config_set_in_file(file_name.buf, "core.worktree",
1241-
relative_path(real_work_tree, git_dir,
1242-
&rel_path));
1242+
relative_path(work_tree, git_dir, &rel_path));
12431243

12441244
strbuf_release(&file_name);
12451245
strbuf_release(&rel_path);
1246-
free((void *)real_work_tree);
1246+
free(work_tree);
1247+
free(git_dir);
12471248
}
12481249

12491250
int parallel_submodules(void)

0 commit comments

Comments
 (0)