* 'git mv' doesn't move submodule if it's in a subdirectory
@ 2016-04-15 8:14 Albin Otterhäll
2016-04-15 17:18 ` Stefan Beller
0 siblings, 1 reply; 7+ messages in thread
From: Albin Otterhäll @ 2016-04-15 8:14 UTC (permalink / raw)
To: git
I've a submodule located in a subdirectory
({git_rep}/home/{directory}/{submodule}), and I wanted to move the whole
directory up a level ({git_rep}/{directory}/{submodule}). But when I
used 'git mv {directory} ../' the '.gitmodule' file didn't get modified.
Best regards,
Albin Otterhäll
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: 'git mv' doesn't move submodule if it's in a subdirectory
2016-04-15 8:14 'git mv' doesn't move submodule if it's in a subdirectory Albin Otterhäll
@ 2016-04-15 17:18 ` Stefan Beller
2016-04-15 17:59 ` Stefan Beller
2016-04-15 19:39 ` 'git mv' doesn't move submodule if it's in a subdirectory Albin Otterhäll
0 siblings, 2 replies; 7+ messages in thread
From: Stefan Beller @ 2016-04-15 17:18 UTC (permalink / raw)
To: Albin Otterhäll; +Cc: git@vger.kernel.org
On Fri, Apr 15, 2016 at 1:14 AM, Albin Otterhäll <gmane@otterhall.com> wrote:
> I've a submodule located in a subdirectory
> ({git_rep}/home/{directory}/{submodule}), and I wanted to move the whole
> directory up a level ({git_rep}/{directory}/{submodule}). But when I
> used 'git mv {directory} ../' the '.gitmodule' file didn't get modified.
>
> Best regards,
> Albin Otterhäll
Thanks for the bug report!
Which version of Git do you use? (Did you try different versions?)
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: 'git mv' doesn't move submodule if it's in a subdirectory
2016-04-15 17:18 ` Stefan Beller
@ 2016-04-15 17:59 ` Stefan Beller
2016-04-15 18:21 ` Junio C Hamano
2016-04-15 19:39 ` 'git mv' doesn't move submodule if it's in a subdirectory Albin Otterhäll
1 sibling, 1 reply; 7+ messages in thread
From: Stefan Beller @ 2016-04-15 17:59 UTC (permalink / raw)
To: Albin Otterhäll; +Cc: git@vger.kernel.org
On Fri, Apr 15, 2016 at 10:18 AM, Stefan Beller <sbeller@google.com> wrote:
> On Fri, Apr 15, 2016 at 1:14 AM, Albin Otterhäll <gmane@otterhall.com> wrote:
>> I've a submodule located in a subdirectory
>> ({git_rep}/home/{directory}/{submodule}), and I wanted to move the whole
>> directory up a level ({git_rep}/{directory}/{submodule}). But when I
>> used 'git mv {directory} ../' the '.gitmodule' file didn't get modified.
>>
>> Best regards,
>> Albin Otterhäll
>
> Thanks for the bug report!
> Which version of Git do you use? (Did you try different versions?)
I think I can reproduce the problem. A regression test (which currently fails)
could look like
diff --git a/t/t7001-mv.sh b/t/t7001-mv.sh
index 4008fae..3b96a9a 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,14 @@ test_expect_success 'mv -k does not accidentally
destroy submodules' '
git checkout .
'
+test_expect_failure 'moving a submodule in nested directories' '
+ (
+ cd deep &&
+ git mv directory ../ &&
+ git status
+ # currently git status exits with 128
+ # fatal: Not a git repository:
directory/hierachy/sub/../../../../.git/modules/deep/directory/hierachy/sub
+ )
+'
+
test_done
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: 'git mv' doesn't move submodule if it's in a subdirectory
2016-04-15 17:59 ` Stefan Beller
@ 2016-04-15 18:21 ` Junio C Hamano
2016-04-15 18:24 ` Stefan Beller
0 siblings, 1 reply; 7+ messages in thread
From: Junio C Hamano @ 2016-04-15 18:21 UTC (permalink / raw)
To: Stefan Beller, Jens Lehmann; +Cc: Albin Otterhäll, git@vger.kernel.org
Stefan Beller <sbeller@google.com> writes:
> I think I can reproduce the problem. A regression test (which currently fails)
> could look like
Thanks. I however do not think this is a regression.
Changes around 0656781f (mv: update the path entry in .gitmodules
for moved submodules, 2013-08-06) did introduce "git mv dir1 dir2"
when 'dir1' is a submodule, but I do not think it went beyond that.
I do not see any effort to treat a submodule that is discovered by
scanning a directory that was given from the command line,
i.e. prepare_move_submodule() is not called for them, and the
entries in the submodule_gitfile[] array that correspond to them are
explicitly set to NULL in the loop.
> diff --git a/t/t7001-mv.sh b/t/t7001-mv.sh
> index 4008fae..3b96a9a 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,14 @@ test_expect_success 'mv -k does not accidentally
> destroy submodules' '
> git checkout .
> '
>
> +test_expect_failure 'moving a submodule in nested directories' '
> + (
> + cd deep &&
> + git mv directory ../ &&
> + git status
> + # currently git status exits with 128
> + # fatal: Not a git repository:
> directory/hierachy/sub/../../../../.git/modules/deep/directory/hierachy/sub
> + )
> +'
> +
> test_done
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: 'git mv' doesn't move submodule if it's in a subdirectory
2016-04-15 18:21 ` Junio C Hamano
@ 2016-04-15 18:24 ` Stefan Beller
2016-04-15 19:11 ` [PATCH] mv: allow moving nested submodules Stefan Beller
0 siblings, 1 reply; 7+ messages in thread
From: Stefan Beller @ 2016-04-15 18:24 UTC (permalink / raw)
To: Junio C Hamano; +Cc: Jens Lehmann, Albin Otterhäll, git@vger.kernel.org
On Fri, Apr 15, 2016 at 11:21 AM, Junio C Hamano <gitster@pobox.com> wrote:
> Stefan Beller <sbeller@google.com> writes:
>
>> I think I can reproduce the problem. A regression test (which currently fails)
>> could look like
>
> Thanks. I however do not think this is a regression.
>
> Changes around 0656781f (mv: update the path entry in .gitmodules
> for moved submodules, 2013-08-06) did introduce "git mv dir1 dir2"
> when 'dir1' is a submodule, but I do not think it went beyond that.
> I do not see any effort to treat a submodule that is discovered by
> scanning a directory that was given from the command line,
> i.e. prepare_move_submodule() is not called for them, and the
> entries in the submodule_gitfile[] array that correspond to them are
> explicitly set to NULL in the loop.
Also I just realize this is not exactly the same bug as reported.
Albin complains about the .gitmodules file not being adjusted, whereas
the test case I wrote breaks commands in your superproject, i.e. `git status`
or `git diff` just dies.
(Manually inspecting the .gitmodules file turns out it is not adjusted as well.)
>
>
>> diff --git a/t/t7001-mv.sh b/t/t7001-mv.sh
>> index 4008fae..3b96a9a 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,14 @@ test_expect_success 'mv -k does not accidentally
>> destroy submodules' '
>> git checkout .
>> '
>>
>> +test_expect_failure 'moving a submodule in nested directories' '
>> + (
>> + cd deep &&
>> + git mv directory ../ &&
>> + git status
>> + # currently git status exits with 128
>> + # fatal: Not a git repository:
>> directory/hierachy/sub/../../../../.git/modules/deep/directory/hierachy/sub
>> + )
>> +'
>> +
>> test_done
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH] mv: allow moving nested submodules
2016-04-15 18:24 ` Stefan Beller
@ 2016-04-15 19:11 ` Stefan Beller
0 siblings, 0 replies; 7+ messages in thread
From: Stefan Beller @ 2016-04-15 19:11 UTC (permalink / raw)
To: gitster; +Cc: git, Jens.Lehmann, gmane, Stefan Beller
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>
---
Albin,
I think this would fix your problem.
Developed on origin/master (it may apply on older versions, though I did not test)
Thanks,
Stefan
builtin/mv.c | 7 +++++--
t/t7001-mv.sh | 16 ++++++++++++++++
2 files changed, 21 insertions(+), 2 deletions(-)
diff --git a/builtin/mv.c b/builtin/mv.c
index aeae855..65fff11 100644
--- a/builtin/mv.c
+++ b/builtin/mv.c
@@ -252,9 +252,12 @@ 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)
+ if (!show_only) {
+ if (mode != INDEX &&
+ 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]);
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.g630c034
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: 'git mv' doesn't move submodule if it's in a subdirectory
2016-04-15 17:18 ` Stefan Beller
2016-04-15 17:59 ` Stefan Beller
@ 2016-04-15 19:39 ` Albin Otterhäll
1 sibling, 0 replies; 7+ messages in thread
From: Albin Otterhäll @ 2016-04-15 19:39 UTC (permalink / raw)
To: git
On 2016-04-15 19:18, Stefan Beller wrote:
> On Fri, Apr 15, 2016 at 1:14 AM, Albin Otterhäll <gmane@otterhall.com> wrote:
>> I've a submodule located in a subdirectory
>> ({git_rep}/home/{directory}/{submodule}), and I wanted to move the whole
>> directory up a level ({git_rep}/{directory}/{submodule}). But when I
>> used 'git mv {directory} ../' the '.gitmodule' file didn't get modified.
>>
>> Best regards,
>> Albin Otterhäll
>
> Thanks for the bug report!
> Which version of Git do you use? (Did you try different versions?)
>
I'm using 2.8.0 (on an Arch system). Haven't tested on any other version.
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2016-04-15 19:45 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-04-15 8:14 'git mv' doesn't move submodule if it's in a subdirectory Albin Otterhäll
2016-04-15 17:18 ` Stefan Beller
2016-04-15 17:59 ` Stefan Beller
2016-04-15 18:21 ` Junio C Hamano
2016-04-15 18:24 ` Stefan Beller
2016-04-15 19:11 ` [PATCH] mv: allow moving nested submodules Stefan Beller
2016-04-15 19:39 ` 'git mv' doesn't move submodule if it's in a subdirectory Albin Otterhäll
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 NNTP newsgroup(s).