submodule--helper.c: remove duplicate code
Remove code fragment from module_clone that duplicates functionality of connect_work_tree_and_git_dir in dir.c Signed-off-by: Valery Tolstov <me@vtolstov.org> Reviewed-by: Brandon Williams <bmwill@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com> Signed-off-by: Stefan Beller <sbeller@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Valery Tolstov committed
Mar 14, 2017 at 14:46 UTC
4682085cd4bfdd6adbe2d5afcfab01d6a116b7d9
1 file changed
+2
-20
builtin/submodule--helper.c
+2
-20
@@ -579,9 +579,7 @@ static int module_clone(int argc, const char **argv, const char *prefix)
579
const char *name = NULL, *url = NULL, *depth = NULL;
580
int quiet = 0;
581
int progress = 0;
582
- FILE *submodule_dot_git;
582
char *p, *path = NULL, *sm_gitdir;
584
- struct strbuf rel_path = STRBUF_INIT;
583
struct strbuf sb = STRBUF_INIT;
584
struct string_list reference = STRING_LIST_INIT_NODUP;
585
char *sm_alternate = NULL, *error_strategy = NULL;
@@ -653,27 +651,12 @@ static int module_clone(int argc, const char **argv, const char *prefix)
651
strbuf_reset(&sb);
652
}
653
656
- /* Write a .git file in the submodule to redirect to the superproject. */
657
- strbuf_addf(&sb, "%s/.git", path);
658
- if (safe_create_leading_directories_const(sb.buf) < 0)
659
- die(_("could not create leading directories of '%s'"), sb.buf);
660
- submodule_dot_git = fopen(sb.buf, "w");
661
- if (!submodule_dot_git)
662
- die_errno(_("cannot open file '%s'"), sb.buf);
663
-
664
- fprintf_or_die(submodule_dot_git, "gitdir: %s\n",
665
- relative_path(sm_gitdir, path, &rel_path));
666
- if (fclose(submodule_dot_git))
667
- die(_("could not close file %s"), sb.buf);
668
- strbuf_reset(&sb);
669
- strbuf_reset(&rel_path);
654
+ /* Connect module worktree and git dir */
655
+ connect_work_tree_and_git_dir(path, sm_gitdir);
656
671
- /* Redirect the worktree of the submodule in the superproject's config */
657
p = git_pathdup_submodule(path, "config");
658
if (!p)
659
die(_("could not get submodule directory for '%s'"), path);
675
- git_config_set_in_file(p, "core.worktree",
676
- relative_path(path, sm_gitdir, &rel_path));
660
661
/* setup alternateLocation and alternateErrorStrategy in the cloned submodule if needed */
662
git_config_get_string("submodule.alternateLocation", &sm_alternate);
@@ -689,7 +672,6 @@ static int module_clone(int argc, const char **argv, const char *prefix)
672
free(error_strategy);
673
674
strbuf_release(&sb);
692
- strbuf_release(&rel_path);
675
free(sm_gitdir);
676
free(path);
677
free(p);