threads / discuss / 35507

mv/rm submodules

Subject: mv/rm submodules

## tl;dr

8 messages between Dec 9, 2013 and Jan 7, 2014.

replies: 7people: 3as markdown or json

George Papanikolaou· Dec 9, 2013, 10:59 UTC · lore
Hi list,

I was just playing with the new features of 'git mv' in 1.8.5 and realized that both rm and mv don't change the .git/config file. Is that on purpuse? Also after mv you need to run 'submodule update' and I think this should be documented somewhere.

Thanks..
-- 
George 'papanikge' Papanikolaou
g3orge.app@gmail.com
Jens Lehmann· Dec 9, 2013, 17:49 UTC · re: George Papanikolaou · lore

Re: mv/rm submodules

Am 09.12.2013 11:59, schrieb George Papanikolaou:
> I was just playing with the new features of 'git mv' in 1.8.5 and
> realized that both rm
> and mv don't change the .git/config file. Is that on purpuse?

Yes. Only the "path" entry in .gitmodules needs to be updated when a submodule is moved. Its name stays the same and thus the .git/config entry automatically applies to the new location.

> Also after mv you need to run 'submodule update' and I think this should be
> documented somewhere.

You're right, this should be mentioned in the mv man page. I'll prepare a patch for that.

Thanks for your feedback.
Jens Lehmann· Jan 6, 2014, 19:21 UTC · re: Jens Lehmann · lore

[PATCH] mv: better document side effects when moving a submodule

The "Submodules" section of the "git mv" documentation mentions what will happen when a submodule with a gitfile gets moved with newer git. But it doesn't talk about what happens when the user changes between commits before and after the move, which does not update the work tree like using the mv command did the first time.

Explain what happens and what the user has to do manually to fix that. Also document this in a new test.

Reported-by: George Papanikolaou <g3orge.app@gmail.com>
Signed-off-by: Jens Lehmann <Jens.Lehmann@web.de>
---
Am 09.12.2013 18:49, schrieb Jens Lehmann:
Show 6 quoted lines
> Am 09.12.2013 11:59, schrieb George Papanikolaou:
>> Also after mv you need to run 'submodule update' and I think this should be
>> documented somewhere.
> 
> You're right, this should be mentioned in the mv man page. I'll
> prepare a patch for that.
Does this new paragraph make it clearer?
 Documentation/git-mv.txt | 10 ++++++++++
 t/t7001-mv.sh            | 21 +++++++++++++++++++++
 2 files changed, 31 insertions(+)
diff --git a/Documentation/git-mv.txt b/Documentation/git-mv.txt
index b1f7988..c9e8568 100644
--- a/Documentation/git-mv.txt
+++ b/Documentation/git-mv.txt
@@ -52,6 +52,16 @@ core.worktree setting to make the submodule work in the new location.
 It also will attempt to update the submodule.<name>.path setting in
 the linkgit:gitmodules[5] file and stage that file (unless -n is used).

+Please note that each time a superproject update moves a populated
+submodule (e.g. when switching between commits before and after the
+move) a stale submodule checkout will remain in the old location
+and an empty directory will appear in the new location. To populate
+the submodule again in the new location the user will have to run
+"git submodule update" afterwards. Removing the old directory is
+only safe when it uses a gitfile, as otherwise the history of the
+submodule will be deleted too. Both steps will be obsolete when
+recursive submodule update has been implemented.
+
 GIT
 ---
 Part of the linkgit:git[1] suite
diff --git a/t/t7001-mv.sh b/t/t7001-mv.sh
index 3bfdfed..e3c8c2c 100755
--- a/t/t7001-mv.sh
+++ b/t/t7001-mv.sh
@@ -442,4 +442,25 @@ test_expect_success 'mv --dry-run does not touch the submodule or .gitmodules' '
 	git diff-files --quiet -- sub .gitmodules
 '

+test_expect_success 'checking out a commit before submodule moved needs manual updates' '
+	git mv sub sub2 &&
+	git commit -m "moved sub to sub2" &&
+	git checkout -q HEAD^ 2>actual &&
+	echo "warning: unable to rmdir sub2: Directory not empty" >expected &&
+	test_i18ncmp expected actual &&
+	git status -s sub2 >actual &&
+	echo "?? sub2/" >expected &&
+	test_cmp expected actual &&
+	! test -f sub/.git &&
+	test -f sub2/.git &&
+	git submodule update &&
+	test -f sub/.git &&
+	rm -rf sub2 &&
+	git diff-index --exit-code HEAD &&
+	git update-index --refresh &&
+	git diff-files --quiet -- sub .gitmodules &&
+	git status -s sub2 >actual &&
+	! test -s actual
+'
+
 test_done
-- 
1.8.5.2.230.g9325930
Junio C Hamano· Jan 6, 2014, 22:40 UTC · re: Jens Lehmann · lore

Re: [PATCH] mv: better document side effects when moving a submodule

Jens Lehmann <Jens.Lehmann@web.de> writes:
Show 22 quoted lines
> The "Submodules" section of the "git mv" documentation mentions what will
> happen when a submodule with a gitfile gets moved with newer git. But it
> doesn't talk about what happens when the user changes between commits
> before and after the move, which does not update the work tree like using
> the mv command did the first time.
>
> Explain what happens and what the user has to do manually to fix that.
> Also document this in a new test.
>
> Reported-by: George Papanikolaou <g3orge.app@gmail.com>
> Signed-off-by: Jens Lehmann <Jens.Lehmann@web.de>
> ---
>
> Am 09.12.2013 18:49, schrieb Jens Lehmann:
>> Am 09.12.2013 11:59, schrieb George Papanikolaou:
>>> Also after mv you need to run 'submodule update' and I think this should be
>>> documented somewhere.
>> 
>> You're right, this should be mentioned in the mv man page. I'll
>> prepare a patch for that.
>
> Does this new paragraph make it clearer?

Don't we have bugs section that we can use to list the known limitations like this?

>  Documentation/git-mv.txt | 10 ++++++++++
>  t/t7001-mv.sh            | 21 +++++++++++++++++++++

It also may make sense to express the test as "this is what we would like to see happen eventually" in the form of test_expect_failure; it is not a big deal though.

Show 53 quoted lines
>  2 files changed, 31 insertions(+)
>
> diff --git a/Documentation/git-mv.txt b/Documentation/git-mv.txt
> index b1f7988..c9e8568 100644
> --- a/Documentation/git-mv.txt
> +++ b/Documentation/git-mv.txt
> @@ -52,6 +52,16 @@ core.worktree setting to make the submodule work in the new location.
>  It also will attempt to update the submodule.<name>.path setting in
>  the linkgit:gitmodules[5] file and stage that file (unless -n is used).
>
> +Please note that each time a superproject update moves a populated
> +submodule (e.g. when switching between commits before and after the
> +move) a stale submodule checkout will remain in the old location
> +and an empty directory will appear in the new location. To populate
> +the submodule again in the new location the user will have to run
> +"git submodule update" afterwards. Removing the old directory is
> +only safe when it uses a gitfile, as otherwise the history of the
> +submodule will be deleted too. Both steps will be obsolete when
> +recursive submodule update has been implemented.
> +
>  GIT
>  ---
>  Part of the linkgit:git[1] suite
> diff --git a/t/t7001-mv.sh b/t/t7001-mv.sh
> index 3bfdfed..e3c8c2c 100755
> --- a/t/t7001-mv.sh
> +++ b/t/t7001-mv.sh
> @@ -442,4 +442,25 @@ test_expect_success 'mv --dry-run does not touch the submodule or .gitmodules' '
>  	git diff-files --quiet -- sub .gitmodules
>  '
>
> +test_expect_success 'checking out a commit before submodule moved needs manual updates' '
> +	git mv sub sub2 &&
> +	git commit -m "moved sub to sub2" &&
> +	git checkout -q HEAD^ 2>actual &&
> +	echo "warning: unable to rmdir sub2: Directory not empty" >expected &&
> +	test_i18ncmp expected actual &&
> +	git status -s sub2 >actual &&
> +	echo "?? sub2/" >expected &&
> +	test_cmp expected actual &&
> +	! test -f sub/.git &&
> +	test -f sub2/.git &&
> +	git submodule update &&
> +	test -f sub/.git &&
> +	rm -rf sub2 &&
> +	git diff-index --exit-code HEAD &&
> +	git update-index --refresh &&
> +	git diff-files --quiet -- sub .gitmodules &&
> +	git status -s sub2 >actual &&
> +	! test -s actual
> +'
> +
>  test_done
Jens Lehmann· Jan 7, 2014, 17:57 UTC · re: Junio C Hamano · lore

Re: [PATCH] mv: better document side effects when moving a submodule

Am 06.01.2014 23:40, schrieb Junio C Hamano:
Show 5 quoted lines
> Jens Lehmann <Jens.Lehmann@web.de> writes:
>> Does this new paragraph make it clearer?
> 
> Don't we have bugs section that we can use to list the known
> limitations like this?
Right, will change accordingly in v2.
Show 6 quoted lines
>>  Documentation/git-mv.txt | 10 ++++++++++
>>  t/t7001-mv.sh            | 21 +++++++++++++++++++++
> 
> It also may make sense to express the test as "this is what we would
> like to see happen eventually" in the form of test_expect_failure;
> it is not a big deal though.

We'll get the "what we would like to see happen eventually" test for free from the recursive submodule update framework I'm currently implementing, so I propose we don't implement this exepected failure in this patch.

Jens Lehmann· Jan 7, 2014, 21:30 UTC · re: Jens Lehmann · lore

[PATCH v2 0/2] better document side effects when [re]moving a submodule

Am 07.01.2014 18:57, schrieb Jens Lehmann:
Show 8 quoted lines
> Am 06.01.2014 23:40, schrieb Junio C Hamano:
>> Jens Lehmann <Jens.Lehmann@web.de> writes:
>>> Does this new paragraph make it clearer?
>>
>> Don't we have bugs section that we can use to list the known
>> limitations like this?
> 
> Right, will change accordingly in v2.
Changes from v1:
- Document side effects under the BUGS section
- Add similar documentation for "git rm"
Jens Lehmann (2):
  mv: better document side effects when moving a submodule
  rm: better document side effects when removing a submodule
 Documentation/git-mv.txt | 12 ++++++++++++
 Documentation/git-rm.txt |  9 +++++++++
 t/t3600-rm.sh            | 16 ++++++++++++++++
 t/t7001-mv.sh            | 21 +++++++++++++++++++++
 4 files changed, 58 insertions(+)
-- 
1.8.5.2.231.gfc86eb1
Jens Lehmann· Jan 7, 2014, 21:31 UTC · re: Jens Lehmann · lore

[PATCH v2 1/2] mv: better document side effects when moving a submodule

The "Submodules" section of the "git mv" documentation mentions what will happen when a submodule with a gitfile gets moved with newer git. But it doesn't talk about what happens when the user changes between commits before and after the move, which does not update the work tree like using the mv command did the first time.

Explain what happens and what the user has to do manually to fix that in the new BUGS section. Also document this behavior in a new test.

Reported-by: George Papanikolaou <g3orge.app@gmail.com>
Signed-off-by: Jens Lehmann <Jens.Lehmann@web.de>
---
 Documentation/git-mv.txt | 12 ++++++++++++
 t/t7001-mv.sh            | 21 +++++++++++++++++++++
 2 files changed, 33 insertions(+)
diff --git a/Documentation/git-mv.txt b/Documentation/git-mv.txt
index b1f7988..e453132 100644
--- a/Documentation/git-mv.txt
+++ b/Documentation/git-mv.txt
@@ -52,6 +52,18 @@ core.worktree setting to make the submodule work in the new location.
 It also will attempt to update the submodule.<name>.path setting in
 the linkgit:gitmodules[5] file and stage that file (unless -n is used).

+BUGS
+----
+Each time a superproject update moves a populated submodule (e.g. when
+switching between commits before and after the move) a stale submodule
+checkout will remain in the old location and an empty directory will
+appear in the new location. To populate the submodule again in the new
+location the user will have to run "git submodule update"
+afterwards. Removing the old directory is only safe when it uses a
+gitfile, as otherwise the history of the submodule will be deleted
+too. Both steps will be obsolete when recursive submodule update has
+been implemented.
+
 GIT
 ---
 Part of the linkgit:git[1] suite
diff --git a/t/t7001-mv.sh b/t/t7001-mv.sh
index 3bfdfed..e3c8c2c 100755
--- a/t/t7001-mv.sh
+++ b/t/t7001-mv.sh
@@ -442,4 +442,25 @@ test_expect_success 'mv --dry-run does not touch the submodule or .gitmodules' '
 	git diff-files --quiet -- sub .gitmodules
 '

+test_expect_success 'checking out a commit before submodule moved needs manual updates' '
+	git mv sub sub2 &&
+	git commit -m "moved sub to sub2" &&
+	git checkout -q HEAD^ 2>actual &&
+	echo "warning: unable to rmdir sub2: Directory not empty" >expected &&
+	test_i18ncmp expected actual &&
+	git status -s sub2 >actual &&
+	echo "?? sub2/" >expected &&
+	test_cmp expected actual &&
+	! test -f sub/.git &&
+	test -f sub2/.git &&
+	git submodule update &&
+	test -f sub/.git &&
+	rm -rf sub2 &&
+	git diff-index --exit-code HEAD &&
+	git update-index --refresh &&
+	git diff-files --quiet -- sub .gitmodules &&
+	git status -s sub2 >actual &&
+	! test -s actual
+'
+
 test_done
-- 
1.8.5.2.231.gfc86eb1
Jens Lehmann· Jan 7, 2014, 21:32 UTC · re: Jens Lehmann · lore

[PATCH v2 2/2] rm: better document side effects when removing a submodule

The "Submodules" section of the "git rm" documentation mentions what will happen when a submodule with a gitfile gets removed with newer git. But it doesn't talk about what happens when the user changes between commits before and after the removal, which does not remove the submodule from the work tree like using the rm command did the first time.

Explain what happens and what the user has to do manually to fix that in the new BUGS section. Also document this behavior in a new test.

Signed-off-by: Jens Lehmann <Jens.Lehmann@web.de>
---
 Documentation/git-rm.txt |  9 +++++++++
 t/t3600-rm.sh            | 16 ++++++++++++++++
 2 files changed, 25 insertions(+)
diff --git a/Documentation/git-rm.txt b/Documentation/git-rm.txt
index 9d731b4..f1efc11 100644
--- a/Documentation/git-rm.txt
+++ b/Documentation/git-rm.txt
@@ -170,6 +170,15 @@ of files and subdirectories under the `Documentation/` directory.
 	(i.e. you are listing the files explicitly), it
 	does not remove `subdir/git-foo.sh`.

+BUGS
+----
+Each time a superproject update removes a populated submodule
+(e.g. when switching between commits before and after the removal) a
+stale submodule checkout will remain in the old location. Removing the
+old directory is only safe when it uses a gitfile, as otherwise the
+history of the submodule will be deleted too. This step will be
+obsolete when recursive submodule update has been implemented.
+
 SEE ALSO
 --------
 linkgit:git-add[1]
diff --git a/t/t3600-rm.sh b/t/t3600-rm.sh
index 540c49b..3d30581 100755
--- a/t/t3600-rm.sh
+++ b/t/t3600-rm.sh
@@ -705,6 +705,22 @@ test_expect_success 'rm of a populated nested submodule with a nested .git direc
 	rm -rf submod
 '

+test_expect_success 'checking out a commit after submodule removal needs manual updates' '
+	git commit -m "submodule removal" submod &&
+	git checkout HEAD^ &&
+	git submodule update &&
+	git checkout -q HEAD^ 2>actual &&
+	git checkout -q master 2>actual &&
+	echo "warning: unable to rmdir submod: Directory not empty" >expected &&
+	test_i18ncmp expected actual &&
+	git status -s submod >actual &&
+	echo "?? submod/" >expected &&
+	test_cmp expected actual &&
+	rm -rf submod &&
+	git status -s -uno --ignore-submodules=none > actual &&
+	! test -s actual
+'
+
 test_expect_success 'rm of d/f when d has become a non-directory' '
 	rm -rf d &&
 	mkdir d &&
-- 
1.8.5.2.231.gfc86eb1

← back to recent threads