Skip to contentSkip to conversation

mv/rm submodules

PATCH Superseded George Papanikolaou 3 participants 8 messages Jun 15, 2016 Documentation

lore
Share & tools
lore
#0 lore raw

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..

Signature · 2 lines
George 'papanikge' Papanikolaou
[email protected]
#1 lore raw

Am 09.12.2013 11:59, schrieb George Papanikolaou:

Quoted 3 lines

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.

Quoted 2 lines

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.

#2 lore raw

PATCH 1/1 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.

---

Am 09.12.2013 18:49, schrieb Jens Lehmann:

Quoted 6 lines

Am 09.12.2013 11:59, schrieb George Papanikolaou:

Quoted 2 lines

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(+)
Documentation/git-mv.txt +10 -0
index b1f7988..c9e8568 100644
@@ -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
t/t7001-mv.sh +21 -0
index 3bfdfed..e3c8c2c 100755
@@ -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
Signature · 1 line
1.8.5.2.230.g9325930
#3 lore raw

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

Quoted 14 lines · Jens Lehmann

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.

---

Am 09.12.2013 18:49, schrieb Jens Lehmann:

Quoted 8 lines
Quoted 6 lines

Am 09.12.2013 11:59, schrieb George Papanikolaou:

Quoted 2 lines

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?

Quoted 2 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.

Quoted 53 lines
 2 files changed, 31 insertions(+)
Documentation/git-mv.txt +10 -0
index b1f7988..c9e8568 100644
@@ -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
t/t7001-mv.sh +21 -0
index 3bfdfed..e3c8c2c 100755
@@ -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
#4 lore raw

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

Am 06.01.2014 23:40, schrieb Junio C Hamano:

Quoted 5 lines
Quoted 1 line · Jens Lehmann

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.

Quoted 6 lines
Quoted 2 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.

#5 lore raw

v2 cover better document side effects when [re]moving a submodule

Am 07.01.2014 18:57, schrieb Jens Lehmann:

Quoted 8 lines

Am 06.01.2014 23:40, schrieb Junio C Hamano:

Quoted 5 lines
Quoted 1 line · Jens Lehmann

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(+)
Signature · 1 line
1.8.5.2.231.gfc86eb1
#6 lore raw

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.

---
 Documentation/git-mv.txt | 12 ++++++++++++
 t/t7001-mv.sh            | 21 +++++++++++++++++++++
 2 files changed, 33 insertions(+)
Documentation/git-mv.txt +12 -0
index b1f7988..e453132 100644
@@ -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
t/t7001-mv.sh +21 -0
index 3bfdfed..e3c8c2c 100755
@@ -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
Signature · 1 line
1.8.5.2.231.gfc86eb1
#7 lore raw

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

In reply to Jens Lehmann

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.

---
 Documentation/git-rm.txt |  9 +++++++++
 t/t3600-rm.sh            | 16 ++++++++++++++++
 2 files changed, 25 insertions(+)
Documentation/git-rm.txt +9 -0
index 9d731b4..f1efc11 100644
@@ -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]
t/t3600-rm.sh +16 -0
index 540c49b..3d30581 100755
@@ -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 &&
Signature · 1 line
1.8.5.2.231.gfc86eb1