From: Stefan Beller <sbeller@google.com>
To: git@vger.kernel.org
Cc: gitster@pobox.com, Jens.Lehmann@web.de, gmane@otterhall.com,
Stefan Beller <sbeller@google.com>
Subject: [PATCH 2/2] mv: allow moving nested submodules
Date: Mon, 18 Apr 2016 16:41:24 -0700 [thread overview]
Message-ID: <1461022884-30819-3-git-send-email-sbeller@google.com> (raw)
In-Reply-To: <1461022884-30819-1-git-send-email-sbeller@google.com>
When directories are moved using `git mv` all files in the directory
have been just moved, but no further action was taken on them. This
was done by assigning the mode = WORKING_DIRECTORY to the files
inside a moved directory.
submodules however need to update their link to the git directory as
well as updates to the .gitmodules file. By removing the condition of
`mode != INDEX` (the remaining modes are BOTH and WORKING_DIRECTORY) for
the required submodule actions, we perform these for submodules in a
moved directory.
Signed-off-by: Stefan Beller <sbeller@google.com>
---
builtin/mv.c | 39 ++++++++++++++++++++++-----------------
t/t7001-mv.sh | 16 ++++++++++++++++
2 files changed, 38 insertions(+), 17 deletions(-)
diff --git a/builtin/mv.c b/builtin/mv.c
index 74516f4..2deb95b 100644
--- a/builtin/mv.c
+++ b/builtin/mv.c
@@ -253,23 +253,28 @@ int cmd_mv(int argc, const char **argv, const char *prefix)
int pos;
if (show_only || verbose)
printf(_("Renaming %s to %s\n"), src, dst);
- if (!show_only && mode != INDEX) {
- if (rename(src, dst) < 0 && !ignore_errors)
- die_errno(_("renaming '%s' failed"), src);
- if (submodule_gitfile[i]) {
- if ((submodule_gitfile[i] != SUBMODULE_WITH_GITDIR &&
- connect_work_tree_and_git_dir(dst, submodule_gitfile[i], &err)) ||
- update_path_in_gitmodules(src, dst, &err)) {
- if (err.len) {
- if (ignore_errors) {
- warning("%s", err.buf);
- continue;
- } else
- die("%s", err.buf);
- }
- } else
- gitmodules_modified = 1;
- }
+ if (show_only)
+ continue;
+ if (mode != INDEX &&
+ rename(src, dst) < 0) {
+ if (ignore_errors)
+ continue;
+ die_errno(_("renaming '%s' failed"), src);
+ }
+
+ if (submodule_gitfile[i]) {
+ if ((submodule_gitfile[i] != SUBMODULE_WITH_GITDIR &&
+ connect_work_tree_and_git_dir(dst, submodule_gitfile[i], &err)) ||
+ update_path_in_gitmodules(src, dst, &err)) {
+ if (err.len) {
+ if (ignore_errors) {
+ warning("%s", err.buf);
+ continue;
+ } else
+ die("%s", err.buf);
+ }
+ } else
+ gitmodules_modified = 1;
}
if (mode == WORKING_DIRECTORY)
diff --git a/t/t7001-mv.sh b/t/t7001-mv.sh
index 4008fae..4a2570e 100755
--- a/t/t7001-mv.sh
+++ b/t/t7001-mv.sh
@@ -292,6 +292,9 @@ test_expect_success 'setup submodule' '
echo content >file &&
git add file &&
git commit -m "added sub and file" &&
+ mkdir -p deep/directory/hierachy &&
+ git submodule add ./. deep/directory/hierachy/sub &&
+ git commit -m "added another submodule" &&
git branch submodule
'
@@ -475,4 +478,17 @@ test_expect_success 'mv -k does not accidentally destroy submodules' '
git checkout .
'
+test_expect_success 'moving a submodule in nested directories' '
+ (
+ cd deep &&
+ git mv directory ../ &&
+ # git status would fail if the update of linking git dir to
+ # work dir of the submodule failed.
+ git status &&
+ git config -f ../.gitmodules submodule.deep/directory/hierachy/sub.path >../actual &&
+ echo "directory/hierachy/sub" >../expect
+ ) &&
+ test_cmp actual expect
+'
+
test_done
--
2.8.1.211.g24879d1
next prev parent reply other threads:[~2016-04-18 23:41 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-04-18 23:41 [PATCH 0/2] WAS: [PATCH] mv: allow moving nested submodules Stefan Beller
2016-04-18 23:41 ` [PATCH 1/2] mv submodule: respect ignore_errors for errors in submodule code Stefan Beller
2016-04-18 23:41 ` Stefan Beller [this message]
2016-04-19 7:13 ` [PATCH 2/2] mv: allow moving nested submodules Jacob Keller
2016-04-19 0:01 ` [PATCH 0/2] WAS: [PATCH] " Junio C Hamano
2016-04-19 16:56 ` Stefan Beller
2016-04-19 18:15 ` Junio C Hamano
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: http://vger.kernel.org/majordomo-info.html
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1461022884-30819-3-git-send-email-sbeller@google.com \
--to=sbeller@google.com \
--cc=Jens.Lehmann@web.de \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=gmane@otterhall.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://80x24.org/mirrors/git.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).