aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNguyễn Thái Ngọc Duy <pclouds@gmail.com>2014-08-10 09:29:31 +0700
committerJunio C Hamano <gitster@pobox.com>2014-09-03 14:59:40 -0700
commit3af05a6d0da3addbcc050f3b1a1ac379e6c4025c (patch)
tree498f2faaa8b5fc1e22de70dcf182043feb9b5e48
parentad1a19d0e7cdd69fd4902b80ab691d43b102e3e2 (diff)
downloadgit-3af05a6d0da3addbcc050f3b1a1ac379e6c4025c.tar.gz
git-3af05a6d0da3addbcc050f3b1a1ac379e6c4025c.tar.xz
mv: split submodule move preparation code out
"Huh?" is removed from die() message. Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
-rw-r--r--builtin/mv.c36
1 files changed, 22 insertions, 14 deletions
diff --git a/builtin/mv.c b/builtin/mv.c
index c48129e30..5a8ff0004 100644
--- a/builtin/mv.c
+++ b/builtin/mv.c
@@ -61,6 +61,23 @@ static const char *add_slash(const char *path)
static struct lock_file lock_file;
#define SUBMODULE_WITH_GITDIR ((const char *)1)
+static void prepare_move_submodule(const char *src, int first,
+ const char **submodule_gitfile)
+{
+ struct strbuf submodule_dotgit = STRBUF_INIT;
+ if (!S_ISGITLINK(active_cache[first]->ce_mode))
+ die(_("Directory %s is in index and no submodule?"), src);
+ if (!is_staging_gitmodules_ok())
+ die(_("Please stage your changes to .gitmodules or stash them to proceed"));
+ strbuf_addf(&submodule_dotgit, "%s/.git", src);
+ *submodule_gitfile = read_gitfile(submodule_dotgit.buf);
+ if (*submodule_gitfile)
+ *submodule_gitfile = xstrdup(*submodule_gitfile);
+ else
+ *submodule_gitfile = SUBMODULE_WITH_GITDIR;
+ strbuf_release(&submodule_dotgit);
+}
+
int cmd_mv(int argc, const char **argv, const char *prefix)
{
int i, gitmodules_modified = 0;
@@ -132,20 +149,11 @@ int cmd_mv(int argc, const char **argv, const char *prefix)
bad = _("cannot move directory over file");
else if (src_is_dir) {
int first = cache_name_pos(src, length);
- if (first >= 0) {
- struct strbuf submodule_dotgit = STRBUF_INIT;
- if (!S_ISGITLINK(active_cache[first]->ce_mode))
- die (_("Huh? Directory %s is in index and no submodule?"), src);
- if (!is_staging_gitmodules_ok())
- die (_("Please, stage your changes to .gitmodules or stash them to proceed"));
- strbuf_addf(&submodule_dotgit, "%s/.git", src);
- submodule_gitfile[i] = read_gitfile(submodule_dotgit.buf);
- if (submodule_gitfile[i])
- submodule_gitfile[i] = xstrdup(submodule_gitfile[i]);
- else
- submodule_gitfile[i] = SUBMODULE_WITH_GITDIR;
- strbuf_release(&submodule_dotgit);
- } else {
+
+ if (first >= 0)
+ prepare_move_submodule(src, first,
+ submodule_gitfile + i);
+ else {
const char *src_w_slash = add_slash(src);
int last, len_w_slash = length + 1;