Skip to content

Commit 3af05a6

Browse files
pcloudsgitster
authored andcommitted
mv: split submodule move preparation code out
"Huh?" is removed from die() message. Signed-off-by: Nguyễn Thái Ngọc Duy <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent ad1a19d commit 3af05a6

File tree

1 file changed

+22
-14
lines changed

1 file changed

+22
-14
lines changed

builtin/mv.c

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,23 @@ static const char *add_slash(const char *path)
6161
static struct lock_file lock_file;
6262
#define SUBMODULE_WITH_GITDIR ((const char *)1)
6363

64+
static void prepare_move_submodule(const char *src, int first,
65+
const char **submodule_gitfile)
66+
{
67+
struct strbuf submodule_dotgit = STRBUF_INIT;
68+
if (!S_ISGITLINK(active_cache[first]->ce_mode))
69+
die(_("Directory %s is in index and no submodule?"), src);
70+
if (!is_staging_gitmodules_ok())
71+
die(_("Please stage your changes to .gitmodules or stash them to proceed"));
72+
strbuf_addf(&submodule_dotgit, "%s/.git", src);
73+
*submodule_gitfile = read_gitfile(submodule_dotgit.buf);
74+
if (*submodule_gitfile)
75+
*submodule_gitfile = xstrdup(*submodule_gitfile);
76+
else
77+
*submodule_gitfile = SUBMODULE_WITH_GITDIR;
78+
strbuf_release(&submodule_dotgit);
79+
}
80+
6481
int cmd_mv(int argc, const char **argv, const char *prefix)
6582
{
6683
int i, gitmodules_modified = 0;
@@ -132,20 +149,11 @@ int cmd_mv(int argc, const char **argv, const char *prefix)
132149
bad = _("cannot move directory over file");
133150
else if (src_is_dir) {
134151
int first = cache_name_pos(src, length);
135-
if (first >= 0) {
136-
struct strbuf submodule_dotgit = STRBUF_INIT;
137-
if (!S_ISGITLINK(active_cache[first]->ce_mode))
138-
die (_("Huh? Directory %s is in index and no submodule?"), src);
139-
if (!is_staging_gitmodules_ok())
140-
die (_("Please, stage your changes to .gitmodules or stash them to proceed"));
141-
strbuf_addf(&submodule_dotgit, "%s/.git", src);
142-
submodule_gitfile[i] = read_gitfile(submodule_dotgit.buf);
143-
if (submodule_gitfile[i])
144-
submodule_gitfile[i] = xstrdup(submodule_gitfile[i]);
145-
else
146-
submodule_gitfile[i] = SUBMODULE_WITH_GITDIR;
147-
strbuf_release(&submodule_dotgit);
148-
} else {
152+
153+
if (first >= 0)
154+
prepare_move_submodule(src, first,
155+
submodule_gitfile + i);
156+
else {
149157
const char *src_w_slash = add_slash(src);
150158
int last, len_w_slash = length + 1;
151159

0 commit comments

Comments
 (0)