submodule: absorb git dir instead of dying on deinit
PATCH 1/1 submodule: absorb git dir instead of dying on deinit
From: mugdha <[email protected]>
Currently, running 'git submodule deinit' on repos where the submodule's '.git' is a folder aborts with a message that is not exactly user friendly. Let's change this to instead warn the user to rerun the command with '--force'.
This internally calls 'absorb_git_dir_into_superproject()', which moves the '.git' folder into the superproject and replaces it with a '.git' file. The rest of the deinit function can operate as it already does with new-style submodules.
We also edit a test case such that it matches the new behaviour of deinit.
---
submodule: absorb git dir instead of dying on deinit
We also edit a test case such that it matches the new behaviour of deinit.
I have changed the 'cp -R ../.git/modules/example .git' to 'mv ../.git/modules/example .git' since, at the time of testing, the test would fail - deinit now would be moving the '.git' folder into the superproject's '.git/modules/' folder, and since this same folder already existed before, it was causing errors. So, before running deinit, instead of copying the '.git' folder into the submodule, if we move it there instead, this functionality can be appropriately tested.
Thank you, Mugdha
Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-git-1078%2Fmugdhapattnaik%2Fsubmodule-deinit-absorbgitdirs-v1
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-git-1078/mugdhapattnaik/submodule-deinit-absorbgitdirs-v1
Pull-Request: https://github.com/git/git/pull/1078
builtin/submodule--helper.c | 27 +++++++++++++++++---------- t/t7400-submodule-basic.sh | 10 +++++----- 2 files changed, 22 insertions(+), 15 deletions(-)
builtin/submodule--helper.c +17 -10
@@ -1539,16 +1539,23 @@ static void deinit_submodule(const char *path, const char *prefix,struct strbuf sb_rm =STRBUF_INIT ;const char *format; -/* -* protect submodules containing a .git directory -* NEEDSWORK: instead of dying, automatically call -* absorbgitdirs and (possibly) warn. -*/ -if (is_directory (sub_git_dir)) -die (_ ("Submodule work tree '%s' contains a .git " -"directory (use 'rm -rf' if you really want " -"to remove it including all of its history)" ), - displaypath); +if (is_directory (sub_git_dir)) { +if (!(flags &OPT_FORCE )) +die (_ ("Submodule work tree '%s' contains a " +".git directory (use --force if you want " +"to move its contents to superproject's " +"module folder and convert .git to a file " +"and then proceed with deinit)" ), + displaypath); + +if (!(flags &OPT_QUIET )) { +warning (_ ("Submodule work tree '%s' contains a .git " +"directory (this will be replaced with a " +".git file by using absorbgitdirs" ), + displaypath); +absorb_git_dir_into_superproject (displaypath, flags); + } + }if (!(flags &OPT_FORCE )) {struct child_process cp_rm =CHILD_PROCESS_INIT ;
t/t7400-submodule-basic.sh +5 -5
@@ -1182,18 +1182,18 @@ test_expect_success 'submodule deinit is silent when used on an uninitialized su rmdir init example2 ' -test_expect_success 'submodule deinit fails when submodule has a .git directory even when forced' ' +test_expect_success 'submodule deinit fails when submodule has a .git directory unless forced' ' git submodule update --init && ( cd init && rm .git && - cp -R ../.git/modules/example .git && + mv ../.git/modules/example .git && GIT_WORK_TREE=. git config --unset core.worktree ) && test_must_fail git submodule deinit init && - test_must_fail git submodule deinit -f init && - test -d init/.git && - test -n "$(git config --get-regexp "submodule\.example\.")" + git submodule deinit -f init && + ! test -d init/.git && + test -z "$(git config --get-regexp "submodule\.example\.")" ' test_expect_success 'submodule with UTF-8 name' '
base-commit: c4203212e360b25a1c69467b5a8437d45a373cac
Signature · 1 line
gitgitgadget
PATCH v2 1/1 submodule: absorb git dir instead of dying on deinit
From: mugdha <[email protected]>
Currently, running 'git submodule deinit' on repos where the submodule's '.git' is a folder aborts with a message that is not exactly user friendly. Let's change this to instead warn the user to rerun the command with '--force'.
This internally calls 'absorb_git_dir_into_superproject()', which moves the '.git' folder into the superproject and replaces it with a '.git' file. The rest of the deinit function can operate as it already does with new-style submodules.
We also edit a test case such that it matches the new behaviour of deinit.
---
submodule: absorb git dir instead of dying on deinit
We also edit a test case such that it matches the new behaviour of deinit.
I have changed the 'cp -R ../.git/modules/example .git' to 'mv ../.git/modules/example .git' since, at the time of testing, the test would fail - deinit now would be moving the '.git' folder into the superproject's '.git/modules/' folder, and since this same folder already existed before, it was causing errors. So, before running deinit, instead of copying the '.git' folder into the submodule, if we move it there instead, this functionality can be appropriately tested.
Changes since v1:
* Removed extra indent within the if statements
* Moved absorb_git_dir_into_superproject() call outside the if condition checking for --quiet flag
Thank you, Mugdha
Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-git-1078%2Fmugdhapattnaik%2Fsubmodule-deinit-absorbgitdirs-v2
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-git-1078/mugdhapattnaik/submodule-deinit-absorbgitdirs-v2
Pull-Request: https://github.com/git/git/pull/1078
Range-diff vs v1:
1: 58814531d17 ! 1: 37c9b598fde submodule: absorb git dir instead of dying on deinit
@@ builtin/submodule--helper.c: static void deinit_submodule(const char *path, cons
- displaypath);
+ if (is_directory(sub_git_dir)) {
+ if (!(flags & OPT_FORCE))
-+ die(_("Submodule work tree '%s' contains a "
-+ ".git directory (use --force if you want "
-+ "to move its contents to superproject's "
-+ "module folder and convert .git to a file "
-+ "and then proceed with deinit)"),
++ die(_("Submodule work tree '%s' contains a "
++ ".git directory.\nUse --force if you want "
++ "to move its contents to superproject's "
++ "module folder and convert .git to a file "
++ "and then proceed with deinit."),
++ displaypath);
++
++ if (!(flags & OPT_QUIET))
++ warning(_("Submodule work tree '%s' contains a .git "
++ "directory. This will be replaced with a "
++ ".git file by using absorbgitdirs."),
+ displaypath);
+
-+ if (!(flags & OPT_QUIET)) {
-+ warning(_("Submodule work tree '%s' contains a .git "
-+ "directory (this will be replaced with a "
-+ ".git file by using absorbgitdirs"),
-+ displaypath);
-+ absorb_git_dir_into_superproject(displaypath, flags);
-+ }
++ absorb_git_dir_into_superproject(displaypath, flags);
++
+ }
if (!(flags & OPT_FORCE)) {builtin/submodule--helper.c | 28 ++++++++++++++++++---------- t/t7400-submodule-basic.sh | 10 +++++----- 2 files changed, 23 insertions(+), 15 deletions(-)
builtin/submodule--helper.c +18 -10
@@ -1539,16 +1539,24 @@ static void deinit_submodule(const char *path, const char *prefix,struct strbuf sb_rm =STRBUF_INIT ;const char *format; -/* -* protect submodules containing a .git directory -* NEEDSWORK: instead of dying, automatically call -* absorbgitdirs and (possibly) warn. -*/ -if (is_directory (sub_git_dir)) -die (_ ("Submodule work tree '%s' contains a .git " -"directory (use 'rm -rf' if you really want " -"to remove it including all of its history)" ), - displaypath); +if (is_directory (sub_git_dir)) { +if (!(flags &OPT_FORCE )) +die (_ ("Submodule work tree '%s' contains a " +".git directory.\nUse --force if you want " +"to move its contents to superproject's " +"module folder and convert .git to a file " +"and then proceed with deinit." ), + displaypath); + +if (!(flags &OPT_QUIET )) +warning (_ ("Submodule work tree '%s' contains a .git " +"directory. This will be replaced with a " +".git file by using absorbgitdirs." ), + displaypath); + +absorb_git_dir_into_superproject (displaypath, flags); + + }if (!(flags &OPT_FORCE )) {struct child_process cp_rm =CHILD_PROCESS_INIT ;
t/t7400-submodule-basic.sh +5 -5
@@ -1182,18 +1182,18 @@ test_expect_success 'submodule deinit is silent when used on an uninitialized su rmdir init example2 ' -test_expect_success 'submodule deinit fails when submodule has a .git directory even when forced' ' +test_expect_success 'submodule deinit fails when submodule has a .git directory unless forced' ' git submodule update --init && ( cd init && rm .git && - cp -R ../.git/modules/example .git && + mv ../.git/modules/example .git && GIT_WORK_TREE=. git config --unset core.worktree ) && test_must_fail git submodule deinit init && - test_must_fail git submodule deinit -f init && - test -d init/.git && - test -n "$(git config --get-regexp "submodule\.example\.")" + git submodule deinit -f init && + ! test -d init/.git && + test -z "$(git config --get-regexp "submodule\.example\.")" ' test_expect_success 'submodule with UTF-8 name' '
base-commit: c4203212e360b25a1c69467b5a8437d45a373cac
Signature · 1 line
gitgitgadget
Quoted 4 lines · Mugdha Pattnaik via GitGitGadget
Currently, running 'git submodule deinit' on repos where the submodule's '.git' is a folder aborts with a message that is not exactly user friendly. Let's change this to instead warn the user to rerun the command with '--force'.
Maybe the case of "repo inside the repo", with submodule as repo?
Signature · 1 line
An old man doll... just what I always wanted! - Clara
Quoted 1 line · Bagas Sanjaya
Maybe the case of "repo inside the repo", with submodule as repo?
I am not certain what exactly you meant, but this patch deals with "Old-form" submodules. This link (https://git-scm.com/docs/gitsubmodules#_forms)
states that old-style submodules, when deinitialized or deleted, have its Git directory automatically moved to $GIT_DIR/modules/<name>/ of the superproject. This is what this patch sets to achieve. Earlier, running deinit on such a submodule would cause it to fail.
--
Mugdha
Quoted 6 lines · Mugdha Pattnaik via GitGitGadget
From: mugdha <[email protected]>
Currently, running 'git submodule deinit' on repos where the submodule's '.git' is a folder aborts with a message that is not exactly user friendly. Let's change this to instead warn the user to rerun the command with '--force'.
This makes sense, a lot of commands seem to follow this pattern of requiring a user to '--force' when the behaviour might not be different from what is normally expected.
Quoted 4 lines
This internally calls '
absorb_git_dir_into_superproject()', which moves the '.git' folder into the superproject and replaces it with a '.git' file. The rest of the deinit function can operate as it already does with new-style submodules.
Nice. Just like what the NEEDSWORK comment suggested.
Quoted 100 lines
We also edit a test case such that it matches the new behaviour of deinit.
Suggested-by Atharva Raykar <[email protected]>Signed-off-by Mugdha Pattnaik <[email protected]>---
submodule: absorb git dir instead of dying on deinitWe also edit a test case such that it matches the new behaviour of deinit.
I have changed the 'cp -R ../.git/modules/example .git' to 'mv ../.git/modules/example .git' since, at the time of testing, the test would fail - deinit now would be moving the '.git' folder into the superproject's '.git/modules/' folder, and since this same folder already existed before, it was causing errors. So, before running deinit, instead of copying the '.git' folder into the submodule, if we move it there instead, this functionality can be appropriately tested.
Changes since v1:
* Removed extra indent within the if statements
* Movedabsorb_git_dir_into_superproject()call outside the if condition checking for --quiet flagThank you, Mugdha
Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-git-1078%2Fmugdhapattnaik%2Fsubmodule-deinit-absorbgitdirs-v2
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-git-1078/mugdhapattnaik/submodule-deinit-absorbgitdirs-v2
Pull-Request: https://github.com/git/git/pull/1078Range-diff vs v1:
1:
58814531d17! 1:37c9b598fdesubmodule: absorb git dir instead of dying on deinit@@ builtin/submodule--helper.c: static void deinit_submodule(const char *path, cons - displaypath); + if (is_directory(sub_git_dir)) { + if (!(flags & OPT_FORCE)) -+ die(_("Submodule work tree '%s' contains a " -+ ".git directory (use --force if you want " -+ "to move its contents to superproject's " -+ "module folder and convert .git to a file " -+ "and then proceed with deinit)"), ++ die(_("Submodule work tree '%s' contains a " ++ ".git directory.\nUse --force if you want " ++ "to move its contents to superproject's " ++ "module folder and convert .git to a file " ++ "and then proceed with deinit."), ++ displaypath); ++ ++ if (!(flags & OPT_QUIET)) ++ warning(_("Submodule work tree '%s' contains a .git " ++ "directory. This will be replaced with a " ++ ".git file by using absorbgitdirs."), + displaypath); + -+ if (!(flags & OPT_QUIET)) { -+ warning(_("Submodule work tree '%s' contains a .git " -+ "directory (this will be replaced with a " -+ ".git file by using absorbgitdirs"), -+ displaypath); -+ absorb_git_dir_into_superproject(displaypath, flags); -+ } ++ absorb_git_dir_into_superproject(displaypath, flags); ++ + } if (!(flags & OPT_FORCE)) {builtin/submodule--helper.c | 28 ++++++++++++++++++---------- t/t7400-submodule-basic.sh | 10 +++++----- 2 files changed, 23 insertions(+), 15 deletions(-)builtin/submodule--helper.c +8
-10@@ -1539,16 +1539,24 @@ static void deinit_submodule(const char *path, const char *prefix,struct strbuf sb_rm =STRBUF_INIT ;const char *format; -/* -* protect submodules containing a .git directory -* NEEDSWORK: instead of dying, automatically call -* absorbgitdirs and (possibly) warn. -*/ -if (is_directory (sub_git_dir)) -die (_ ("Submodule work tree '%s' contains a .git " -"directory (use 'rm -rf' if you really want " -"to remove it including all of its history)" ), - displaypath); +if (is_directory (sub_git_dir)) { +if (!(flags &OPT_FORCE )) +die (_ ("Submodule work tree '%s' contains a " +".git directory.\nUse --force if you want " +"to move its contents to superproject's " +"module folder and convert .git to a file " +"and then proceed with deinit." ), + displaypath);
builtin/submodule--helper.c static void deinit_submodule(const char *path, const char *prefix, · line 1559
Quoted 10 lines
builtin/submodule--helper.c +10
-0+ +if (!(flags &OPT_QUIET )) +warning (_ ("Submodule work tree '%s' contains a .git " +"directory. This will be replaced with a " +".git file by using absorbgitdirs." ), + displaypath); + +absorb_git_dir_into_superproject (displaypath, flags); + + }
Looks okay to me. The quiet flag suppresses the warning, which is nice.
Quoted 8 lines
builtin/submodule--helper.c +0
-0if (!(flags &OPT_FORCE )) {struct child_process cp_rm =CHILD_PROCESS_INIT ;t/t7400-submodule-basic.sh +0
-0@@ -1182,18 +1182,18 @@ test_expect_success 'submodule deinit is silent when used on an uninitialized su rmdir init example2
t/t7400-submodule-basic.sh test_expect_success 'submodule deinit is silent when used on an uninitialized su · line 1190
Quoted 10 lines
t/t7400-submodule-basic.sh +2
-2' -test_expect_success 'submodule deinit fails when submodule has a .git directory even when forced' ' +test_expect_success 'submodule deinit fails when submodule has a .git directory unless forced' ' git submodule update --init && ( cd init && rm .git && - cp -R ../.git/modules/example .git && + mv ../.git/modules/example .git &&
The original test case was written with the expectation that the deinit won't happen. But now that it will, I suppose an mv was necessary so that absorbgitdirs can write the gitdir back to the original place successfully.
t/t7400-submodule-basic.sh test_expect_success 'submodule deinit is silent when used on an uninitialized su · line 1197
Quoted 10 lines
t/t7400-submodule-basic.sh +3
-3GIT_WORK_TREE=. git config --unset core.worktree ) && test_must_fail git submodule deinit init && - test_must_fail git submodule deinit -f init && - test -d init/.git && - test -n "$(git config --get-regexp "submodule\.example\.")" + git submodule deinit -f init && + ! test -d init/.git && + test -z "$(git config --get-regexp "submodule\.example\.")" '
Likewise here. The test case has been flipped to reflect the new behaviour.
Quoted 3 lines
t/t7400-submodule-basic.sh +0
-0test_expect_success 'submodule with UTF-8 name' 'base-commit:
c4203212e360b25a1c69467b5a8437d45a373cac
BTW, I see you linked downthread the documentation[1] which says:
When [old-form submodules] deinitialized or deleted (see below), the submodule’s Git directory is automatically moved to $GIT_DIR/modules/<name>/ of the superproject.
This was not what Git was doing before this patch, it used to die() out instead. So I think this actually is a bug fix (although I am not sure why the test suite also did not agree with the documentation).
Either way, I think this is a welcome change. Thanks for the patch!
Quoted 13 lines · Atharva Raykar
Quoted 6 lines · Mugdha Pattnaik via GitGitGadget
From: mugdha <[email protected]>
Currently, running 'git submodule deinit' on repos where the submodule's '.git' is a folder aborts with a message that is not exactly user friendly. Let's change this to instead warn the user to rerun the command with '--force'.
This makes sense, a lot of commands seem to follow this pattern of requiring a user to '--force' when the behaviour might not be different from what is normally expected.
Quoted 6 lines
Quoted 4 lines
This internally calls '
absorb_git_dir_into_superproject()', which moves the '.git' folder into the superproject and replaces it with a '.git' file. The rest of the deinit function can operate as it already does with new-style submodules.Nice. Just like what the NEEDSWORK comment suggested.
Indeed. Many use of the word "folder", especially when the thing is called "git dir" in the title, irritates me, though. We use files and directories, not folders.
Quoted 9 lines
BTW, I see you linked downthread the documentation[1] which says:
When [old-form submodules] deinitialized or deleted (see below), the submodule’s Git directory is automatically moved to $GIT_DIR/modules/<name>/ of the superproject.
This was not what Git was doing before this patch, it used to
die()out instead. So I think this actually is a bug fix (although I am not sure why the test suite also did not agree with the documentation).
Curious.
I see the description was added by d4803455 (submodules: overhaul documentation, 2017-06-22), which claimed to "detangle" by "move" various existing pieces of documentation into a new file.
I guess we added a wish without marking it as such ;-)
PATCH v3 1/1 submodule: absorb git dir instead of dying on deinit
In reply to Mugdha Pattnaik via GitGitGadgetFrom: mugdha <[email protected]>
Currently, running 'git submodule deinit' on repos where the submodule's '.git' is a directory, aborts with a message that is not exactly user friendly. Let's change this to instead warn the user to rerun the command with '--force'.
This internally calls 'absorb_git_dir_into_superproject()', which moves the git dir into the superproject and replaces it with a '.git' file. The rest of the deinit function can operate as it already does with new-style submodules.
We also edit a test case such that it matches the new behaviour of deinit.
---
submodule: absorb git dir instead of dying on deinit
Changes since v2:
* Replaced all instances of the word "folder" with either "directory" or "git dir"
Thank you, Mugdha
Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-git-1078%2Fmugdhapattnaik%2Fsubmodule-deinit-absorbgitdirs-v3
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-git-1078/mugdhapattnaik/submodule-deinit-absorbgitdirs-v3
Pull-Request: https://github.com/git/git/pull/1078
Range-diff vs v2:
1: 37c9b598fde ! 1: 1ac65b2458b submodule: absorb git dir instead of dying on deinit
@@ Commit message
submodule: absorb git dir instead of dying on deinit
Currently, running 'git submodule deinit' on repos where the
- submodule's '.git' is a folder aborts with a message that is not
+ submodule's '.git' is a directory, aborts with a message that is not
exactly user friendly. Let's change this to instead warn the user to rerun the command with '--force'.
This internally calls 'absorb_git_dir_into_superproject()', which
- moves the '.git' folder into the superproject and replaces it with
+ moves the git dir into the superproject and replaces it with
a '.git' file. The rest of the deinit function can operate as it already does with new-style submodules.
builtin/submodule--helper.c | 28 ++++++++++++++++++---------- t/t7400-submodule-basic.sh | 10 +++++----- 2 files changed, 23 insertions(+), 15 deletions(-)
builtin/submodule--helper.c +18 -10
@@ -1539,16 +1539,24 @@ static void deinit_submodule(const char *path, const char *prefix,struct strbuf sb_rm =STRBUF_INIT ;const char *format; -/* -* protect submodules containing a .git directory -* NEEDSWORK: instead of dying, automatically call -* absorbgitdirs and (possibly) warn. -*/ -if (is_directory (sub_git_dir)) -die (_ ("Submodule work tree '%s' contains a .git " -"directory (use 'rm -rf' if you really want " -"to remove it including all of its history)" ), - displaypath); +if (is_directory (sub_git_dir)) { +if (!(flags &OPT_FORCE )) +die (_ ("Submodule work tree '%s' contains a " +".git directory.\nUse --force if you want " +"to move its contents to superproject's " +"module folder and convert .git to a file " +"and then proceed with deinit." ), + displaypath); + +if (!(flags &OPT_QUIET )) +warning (_ ("Submodule work tree '%s' contains a .git " +"directory. This will be replaced with a " +".git file by using absorbgitdirs." ), + displaypath); + +absorb_git_dir_into_superproject (displaypath, flags); + + }if (!(flags &OPT_FORCE )) {struct child_process cp_rm =CHILD_PROCESS_INIT ;
t/t7400-submodule-basic.sh +5 -5
@@ -1182,18 +1182,18 @@ test_expect_success 'submodule deinit is silent when used on an uninitialized su rmdir init example2 ' -test_expect_success 'submodule deinit fails when submodule has a .git directory even when forced' ' +test_expect_success 'submodule deinit fails when submodule has a .git directory unless forced' ' git submodule update --init && ( cd init && rm .git && - cp -R ../.git/modules/example .git && + mv ../.git/modules/example .git && GIT_WORK_TREE=. git config --unset core.worktree ) && test_must_fail git submodule deinit init && - test_must_fail git submodule deinit -f init && - test -d init/.git && - test -n "$(git config --get-regexp "submodule\.example\.")" + git submodule deinit -f init && + ! test -d init/.git && + test -z "$(git config --get-regexp "submodule\.example\.")" ' test_expect_success 'submodule with UTF-8 name' '
base-commit: c4203212e360b25a1c69467b5a8437d45a373cac
Signature · 1 line
gitgitgadget
PATCH v4 1/1 submodule: absorb git dir instead of dying on deinit
From: mugdha <[email protected]>
Currently, running 'git submodule deinit' on repos where the submodule's '.git' is a directory, aborts with a message that is not exactly user friendly. Let's change this to instead warn the user to rerun the command with '--force'.
This internally calls 'absorb_git_dir_into_superproject()', which moves the git dir into the superproject and replaces it with a '.git' file. The rest of the deinit function can operate as it already does with new-style submodules.
We also edit a test case such that it matches the new behaviour of deinit.
---
submodule: absorb git dir instead of dying on deinit
Changes since v3:
* Replaced 1 instance of the word "folder" with "directory"
* Fixed tab spacing
Thank you, Mugdha
Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-git-1078%2Fmugdhapattnaik%2Fsubmodule-deinit-absorbgitdirs-v4
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-git-1078/mugdhapattnaik/submodule-deinit-absorbgitdirs-v4
Pull-Request: https://github.com/git/git/pull/1078
Range-diff vs v3:
1: 1ac65b2458b ! 1: 7460fc0e12a submodule: absorb git dir instead of dying on deinit
@@ builtin/submodule--helper.c: static void deinit_submodule(const char *path, cons
+ if (is_directory(sub_git_dir)) {
+ if (!(flags & OPT_FORCE))
+ die(_("Submodule work tree '%s' contains a "
-+ ".git directory.\nUse --force if you want "
-+ "to move its contents to superproject's "
-+ "module folder and convert .git to a file "
-+ "and then proceed with deinit."),
-+ displaypath);
++ ".git directory.\nUse --force if you want "
++ "to move its contents to superproject's "
++ "module directory and convert .git to a file "
++ "and then proceed with deinit."),
++ displaypath);
+
+ if (!(flags & OPT_QUIET))
+ warning(_("Submodule work tree '%s' contains a .git "
-+ "directory. This will be replaced with a "
-+ ".git file by using absorbgitdirs."),
-+ displaypath);
++ "directory. This will be replaced with a "
++ ".git file by using absorbgitdirs."),
++ displaypath);
+
+ absorb_git_dir_into_superproject(displaypath, flags);
+builtin/submodule--helper.c | 28 ++++++++++++++++++---------- t/t7400-submodule-basic.sh | 10 +++++----- 2 files changed, 23 insertions(+), 15 deletions(-)
builtin/submodule--helper.c +18 -10
@@ -1539,16 +1539,24 @@ static void deinit_submodule(const char *path, const char *prefix,struct strbuf sb_rm =STRBUF_INIT ;const char *format; -/* -* protect submodules containing a .git directory -* NEEDSWORK: instead of dying, automatically call -* absorbgitdirs and (possibly) warn. -*/ -if (is_directory (sub_git_dir)) -die (_ ("Submodule work tree '%s' contains a .git " -"directory (use 'rm -rf' if you really want " -"to remove it including all of its history)" ), - displaypath); +if (is_directory (sub_git_dir)) { +if (!(flags &OPT_FORCE )) +die (_ ("Submodule work tree '%s' contains a " +".git directory.\nUse --force if you want " +"to move its contents to superproject's " +"module directory and convert .git to a file " +"and then proceed with deinit." ), + displaypath); + +if (!(flags &OPT_QUIET )) +warning (_ ("Submodule work tree '%s' contains a .git " +"directory. This will be replaced with a " +".git file by using absorbgitdirs." ), + displaypath); + +absorb_git_dir_into_superproject (displaypath, flags); + + }if (!(flags &OPT_FORCE )) {struct child_process cp_rm =CHILD_PROCESS_INIT ;
t/t7400-submodule-basic.sh +5 -5
@@ -1182,18 +1182,18 @@ test_expect_success 'submodule deinit is silent when used on an uninitialized su rmdir init example2 ' -test_expect_success 'submodule deinit fails when submodule has a .git directory even when forced' ' +test_expect_success 'submodule deinit fails when submodule has a .git directory unless forced' ' git submodule update --init && ( cd init && rm .git && - cp -R ../.git/modules/example .git && + mv ../.git/modules/example .git && GIT_WORK_TREE=. git config --unset core.worktree ) && test_must_fail git submodule deinit init && - test_must_fail git submodule deinit -f init && - test -d init/.git && - test -n "$(git config --get-regexp "submodule\.example\.")" + git submodule deinit -f init && + ! test -d init/.git && + test -z "$(git config --get-regexp "submodule\.example\.")" ' test_expect_success 'submodule with UTF-8 name' '
base-commit: c4203212e360b25a1c69467b5a8437d45a373cac
Signature · 1 line
gitgitgadget
Quoted 7 lines · Mugdha Pattnaik via GitGitGadget
From: mugdha <[email protected]>
Currently, running 'git submodule deinit' on repos where the submodule's '.git' is a directory, aborts with a message that is not exactly user friendly. Let's change this to instead warn the user to rerun the command with '--force'.
It seems to me that this patch fell into the cracks. Or did I miss something?
Quoted 10 lines
This internally calls '
absorb_git_dir_into_superproject()', which moves the git dir into the superproject and replaces it with a '.git' file. The rest of the deinit function can operate as it already does with new-style submodules.We also edit a test case such that it matches the new behaviour of deinit.
Suggested-by Atharva Raykar <[email protected]>Signed-off-by Mugdha Pattnaik <[email protected]>
Quoted 120 lines · Mugdha Pattnaik via GitGitGadget
From: mugdha <[email protected]>
Currently, running 'git submodule deinit' on repos where the submodule's '.git' is a directory, aborts with a message that is not exactly user friendly. Let's change this to instead warn the user to rerun the command with '--force'.
This internally calls '
absorb_git_dir_into_superproject()', which moves the git dir into the superproject and replaces it with a '.git' file. The rest of the deinit function can operate as it already does with new-style submodules.We also edit a test case such that it matches the new behaviour of deinit.
Suggested-by Atharva Raykar <[email protected]>Signed-off-by Mugdha Pattnaik <[email protected]>---
submodule: absorb git dir instead of dying on deinitChanges since v3:
* Replaced 1 instance of the word "folder" with "directory"
* Fixed tab spacingThank you, Mugdha
Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-git-1078%2Fmugdhapattnaik%2Fsubmodule-deinit-absorbgitdirs-v4
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-git-1078/mugdhapattnaik/submodule-deinit-absorbgitdirs-v4
Pull-Request: https://github.com/git/git/pull/1078Range-diff vs v3:
1:
1ac65b2458b! 1:7460fc0e12asubmodule: absorb git dir instead of dying on deinit@@ builtin/submodule--helper.c: static void deinit_submodule(const char *path, cons + if (is_directory(sub_git_dir)) { + if (!(flags & OPT_FORCE)) + die(_("Submodule work tree '%s' contains a " -+ ".git directory.\nUse --force if you want " -+ "to move its contents to superproject's " -+ "module folder and convert .git to a file " -+ "and then proceed with deinit."), -+ displaypath); ++ ".git directory.\nUse --force if you want " ++ "to move its contents to superproject's " ++ "module directory and convert .git to a file " ++ "and then proceed with deinit."), ++ displaypath); + + if (!(flags & OPT_QUIET)) + warning(_("Submodule work tree '%s' contains a .git " -+ "directory. This will be replaced with a " -+ ".git file by using absorbgitdirs."), -+ displaypath); ++ "directory. This will be replaced with a " ++ ".git file by using absorbgitdirs."), ++ displaypath); + + absorb_git_dir_into_superproject(displaypath, flags); +builtin/submodule--helper.c | 28 ++++++++++++++++++---------- t/t7400-submodule-basic.sh | 10 +++++----- 2 files changed, 23 insertions(+), 15 deletions(-)builtin/submodule--helper.c +18
-10@@ -1539,16 +1539,24 @@ static void deinit_submodule(const char *path, const char *prefix,struct strbuf sb_rm =STRBUF_INIT ;const char *format; -/* -* protect submodules containing a .git directory -* NEEDSWORK: instead of dying, automatically call -* absorbgitdirs and (possibly) warn. -*/ -if (is_directory (sub_git_dir)) -die (_ ("Submodule work tree '%s' contains a .git " -"directory (use 'rm -rf' if you really want " -"to remove it including all of its history)" ), - displaypath); +if (is_directory (sub_git_dir)) { +if (!(flags &OPT_FORCE )) +die (_ ("Submodule work tree '%s' contains a " +".git directory.\nUse --force if you want " +"to move its contents to superproject's " +"module directory and convert .git to a file " +"and then proceed with deinit." ), + displaypath); + +if (!(flags &OPT_QUIET )) +warning (_ ("Submodule work tree '%s' contains a .git " +"directory. This will be replaced with a " +".git file by using absorbgitdirs." ), + displaypath); + +absorb_git_dir_into_superproject (displaypath, flags); + + }if (!(flags &OPT_FORCE )) {struct child_process cp_rm =CHILD_PROCESS_INIT ;t/t7400-submodule-basic.sh +1
-2@@ -1182,18 +1182,18 @@ test_expect_success 'submodule deinit is silent when used on an uninitialized su rmdir init example2 ' -test_expect_success 'submodule deinit fails when submodule has a .git directory even when forced' ' +test_expect_success 'submodule deinit fails when submodule has a .git directory unless forced' ' git submodule update --init && ( cd init && rm .git && - cp -R ../.git/modules/example .git &&
t/t7400-submodule-basic.sh test_expect_success 'submodule deinit is silent when used on an uninitialized su · line 1196
Quoted 10 lines
t/t7400-submodule-basic.sh +4
-3+ mv ../.git/modules/example .git && GIT_WORK_TREE=. git config --unset core.worktree ) && test_must_fail git submodule deinit init && - test_must_fail git submodule deinit -f init && - test -d init/.git && - test -n "$(git config --get-regexp "submodule\.example\.")" + git submodule deinit -f init && + ! test -d init/.git && + test -z "$(git config --get-regexp "submodule\.example\.")"
I see we don't have a "test_dir_is_missing" for the pre-image, but shouldn't the post-image "! test -d" just be a test_path_is_missing? I.e. should this pass if .git is a file? Probably not...
Quoted 2 lines · On Tue, Sep 28, 2021 Ævar Arnfjörð Bjarmason <[email protected]> wrote:
shouldn't the post-image "! test -d" just be a
test_path_is_missing? I.e. should this pass if .git is a file? Probably not...
I agree, this test should not pass if .git is a file. I'll change it to "test_path_is_missing" and send an update to the patch.
PATCH v5 1/1 submodule: absorb git dir instead of dying on deinit
In reply to Mugdha Pattnaik via GitGitGadgetFrom: mugdha <[email protected]>
Currently, running 'git submodule deinit' on repos where the submodule's '.git' is a directory, aborts with a message that is not exactly user friendly. Let's change this to instead warn the user to rerun the command with '--force'.
This internally calls 'absorb_git_dir_into_superproject()', which moves the git dir into the superproject and replaces it with a '.git' file. The rest of the deinit function can operate as it already does with new-style submodules.
We also edit a test case such that it matches the new behaviour of deinit.
---
submodule: absorb git dir instead of dying on deinit
Changes since v4:
* Changed test case from "! test -d" to "test_path_is_missing"
Thanks
Mugdha
Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-git-1078%2Fmugdhapattnaik%2Fsubmodule-deinit-absorbgitdirs-v5
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-git-1078/mugdhapattnaik/submodule-deinit-absorbgitdirs-v5
Pull-Request: https://github.com/git/git/pull/1078
Range-diff vs v4:
1: 7460fc0e12a = 1: c39cd681e71 submodule: absorb git dir instead of dying on deinit
builtin/submodule--helper.c | 28 ++++++++++++++++++---------- t/t7400-submodule-basic.sh | 10 +++++----- 2 files changed, 23 insertions(+), 15 deletions(-)
builtin/submodule--helper.c +18 -10
@@ -1539,16 +1539,24 @@ static void deinit_submodule(const char *path, const char *prefix,struct strbuf sb_rm =STRBUF_INIT ;const char *format; -/* -* protect submodules containing a .git directory -* NEEDSWORK: instead of dying, automatically call -* absorbgitdirs and (possibly) warn. -*/ -if (is_directory (sub_git_dir)) -die (_ ("Submodule work tree '%s' contains a .git " -"directory (use 'rm -rf' if you really want " -"to remove it including all of its history)" ), - displaypath); +if (is_directory (sub_git_dir)) { +if (!(flags &OPT_FORCE )) +die (_ ("Submodule work tree '%s' contains a " +".git directory.\nUse --force if you want " +"to move its contents to superproject's " +"module directory and convert .git to a file " +"and then proceed with deinit." ), + displaypath); + +if (!(flags &OPT_QUIET )) +warning (_ ("Submodule work tree '%s' contains a .git " +"directory. This will be replaced with a " +".git file by using absorbgitdirs." ), + displaypath); + +absorb_git_dir_into_superproject (displaypath, flags); + + }if (!(flags &OPT_FORCE )) {struct child_process cp_rm =CHILD_PROCESS_INIT ;
t/t7400-submodule-basic.sh +5 -5
@@ -1182,18 +1182,18 @@ test_expect_success 'submodule deinit is silent when used on an uninitialized su rmdir init example2 ' -test_expect_success 'submodule deinit fails when submodule has a .git directory even when forced' ' +test_expect_success 'submodule deinit fails when submodule has a .git directory unless forced' ' git submodule update --init && ( cd init && rm .git && - cp -R ../.git/modules/example .git && + mv ../.git/modules/example .git && GIT_WORK_TREE=. git config --unset core.worktree ) && test_must_fail git submodule deinit init && - test_must_fail git submodule deinit -f init && - test -d init/.git && - test -n "$(git config --get-regexp "submodule\.example\.")" + git submodule deinit -f init && + ! test -d init/.git && + test -z "$(git config --get-regexp "submodule\.example\.")" ' test_expect_success 'submodule with UTF-8 name' '
base-commit: c4203212e360b25a1c69467b5a8437d45a373cac
Signature · 1 line
gitgitgadget
PATCH v6 1/1 submodule: absorb git dir instead of dying on deinit
From: mugdha <[email protected]>
Currently, running 'git submodule deinit' on repos where the submodule's '.git' is a directory, aborts with a message that is not exactly user friendly. Let's change this to instead warn the user to rerun the command with '--force'.
This internally calls 'absorb_git_dir_into_superproject()', which moves the git dir into the superproject and replaces it with a '.git' file. The rest of the deinit function can operate as it already does with new-style submodules.
We also edit a test case such that it matches the new behaviour of deinit.
---
submodule: absorb git dir instead of dying on deinit
Changes since v5:
* Fixed accidental submission of old version
Changes since v4:
* Changed test case from "! test -d" to "test_path_is_missing"
Thank you,
Mugdha
Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-git-1078%2Fmugdhapattnaik%2Fsubmodule-deinit-absorbgitdirs-v6
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-git-1078/mugdhapattnaik/submodule-deinit-absorbgitdirs-v6
Pull-Request: https://github.com/git/git/pull/1078
Range-diff vs v5:
1: c39cd681e71 ! 1: 384a6742388 submodule: absorb git dir instead of dying on deinit
@@ t/t7400-submodule-basic.sh: test_expect_success 'submodule deinit is silent when
- test -d init/.git &&
- test -n "$(git config --get-regexp "submodule\.example\.")"
+ git submodule deinit -f init &&
-+ ! test -d init/.git &&
++ test_path_is_missing init/.git &&
+ test -z "$(git config --get-regexp "submodule\.example\.")"
'builtin/submodule--helper.c | 28 ++++++++++++++++++---------- t/t7400-submodule-basic.sh | 10 +++++----- 2 files changed, 23 insertions(+), 15 deletions(-)
builtin/submodule--helper.c +18 -10
@@ -1539,16 +1539,24 @@ static void deinit_submodule(const char *path, const char *prefix,struct strbuf sb_rm =STRBUF_INIT ;const char *format; -/* -* protect submodules containing a .git directory -* NEEDSWORK: instead of dying, automatically call -* absorbgitdirs and (possibly) warn. -*/ -if (is_directory (sub_git_dir)) -die (_ ("Submodule work tree '%s' contains a .git " -"directory (use 'rm -rf' if you really want " -"to remove it including all of its history)" ), - displaypath); +if (is_directory (sub_git_dir)) { +if (!(flags &OPT_FORCE )) +die (_ ("Submodule work tree '%s' contains a " +".git directory.\nUse --force if you want " +"to move its contents to superproject's " +"module directory and convert .git to a file " +"and then proceed with deinit." ), + displaypath); + +if (!(flags &OPT_QUIET )) +warning (_ ("Submodule work tree '%s' contains a .git " +"directory. This will be replaced with a " +".git file by using absorbgitdirs." ), + displaypath); + +absorb_git_dir_into_superproject (displaypath, flags); + + }if (!(flags &OPT_FORCE )) {struct child_process cp_rm =CHILD_PROCESS_INIT ;
t/t7400-submodule-basic.sh +5 -5
@@ -1182,18 +1182,18 @@ test_expect_success 'submodule deinit is silent when used on an uninitialized su rmdir init example2 ' -test_expect_success 'submodule deinit fails when submodule has a .git directory even when forced' ' +test_expect_success 'submodule deinit fails when submodule has a .git directory unless forced' ' git submodule update --init && ( cd init && rm .git && - cp -R ../.git/modules/example .git && + mv ../.git/modules/example .git && GIT_WORK_TREE=. git config --unset core.worktree ) && test_must_fail git submodule deinit init && - test_must_fail git submodule deinit -f init && - test -d init/.git && - test -n "$(git config --get-regexp "submodule\.example\.")" + git submodule deinit -f init && + test_path_is_missing init/.git && + test -z "$(git config --get-regexp "submodule\.example\.")" ' test_expect_success 'submodule with UTF-8 name' '
base-commit: c4203212e360b25a1c69467b5a8437d45a373cac
Signature · 1 line
gitgitgadget
Quoted 1 line · Mugdha Pattnaik via GitGitGadget
From: mugdha <[email protected]>
This line is called "in-body header" that is used to override the author name that is automatically obtained from the e-mail's "From:" header (which is set to "Mugdha Pattnaik via GitGitGadget" by GGG, which is obviously not your name, hence we use an in-body header to override it). It should match what you use to sign off your patches, the one we see below.
I'll hand-edit so that "git show" will say that the author is "Mugdha Pattnaik", not "mugdha", while applying, but please make sure your further submissions will not have this problem.
Quoted 4 lines
Currently, running 'git submodule deinit' on repos where the submodule's '.git' is a directory, aborts with a message that is not exactly user friendly. Let's change this to instead warn the user to rerun the command with '--force'.
OK. That sounds like an improvement, albeit possibly an overly cautious one, as a casual "deinit" user will get an error as before without "--force", which may or may not be a good thing. Requiring "--force" means it is safer by default by not changing the on-disk data. But requiring "--force" also means we end up training users to say "--force" when it shouldn't have to be.
A plausible alternative is to always absorb but with a warning "we absorbed it for you", without requiring "--force". If we didn't have "git submodule deinit" command now and were designing it from scratch, would we design it to fail because the submodule's git directory is not absorbed? I doubt it, as I do not think of a good reason to do so offhand.
Does "git submodule" currently reject a "deinit" request due to some _other_ conditions or safety concerns and require the "--force" option to continue? Requiring the "--force" option to resolve ".git is a directory, and the user wants to make it absorbed" means that the user will be _forced_ to bypass these _other_ safety valves only to save the submodule repository from destruction when running "deinit", which may not be a good trade-off between the safety requirements of these _other_ conditions, if exists, and the one we are dealing with.
Quoted 4 lines
This internally calls '
absorb_git_dir_into_superproject()', which moves the git dir into the superproject and replaces it with a '.git' file. The rest of the deinit function can operate as it already does with new-style submodules.
This is not wrong per-se, but such an implementation detail is something best left for the patch.
Quoted 2 lines
We also edit a test case such that it matches the new behaviour of deinit.
"match the new behaviour" in what way?
In one test, we used to require "git submodule deinit" to fail even with the "--force" option when the submodule's .git/ directory is not absorbed. Adjust it to expect the operation to pass.
would be a description at the right level of detail, I think.
Quoted 24 lines
builtin/submodule--helper.c +6
-10@@ -1539,16 +1539,24 @@ static void deinit_submodule(const char *path, const char *prefix,struct strbuf sb_rm =STRBUF_INIT ;const char *format; -/* -* protect submodules containing a .git directory -* NEEDSWORK: instead of dying, automatically call -* absorbgitdirs and (possibly) warn. -*/ -if (is_directory (sub_git_dir)) -die (_ ("Submodule work tree '%s' contains a .git " -"directory (use 'rm -rf' if you really want " -"to remove it including all of its history)" ), - displaypath); +if (is_directory (sub_git_dir)) { +if (!(flags &OPT_FORCE )) + die(_("Submodule work tree '%s' contains a " + ".git directory.\nUse --force if you want " + "to move its contents to superproject's " + "module directory and convert .git to a file "
builtin/submodule--helper.c static void deinit_submodule(const char *path, const char *prefix, · line 1557
Quoted 10 lines
builtin/submodule--helper.c +10
-0+ "and then proceed with deinit."), + displaypath); + +if (!(flags &OPT_QUIET )) +warning (_ ("Submodule work tree '%s' contains a .git " +"directory. This will be replaced with a " +".git file by using absorbgitdirs." ), + displaypath); + +absorb_git_dir_into_superproject (displaypath, flags);
Shouldn't the first argument to this call be "path" not "displaypath"? The paths in messages may want to have the path from the top to the submodule location prefixed for human consumption, but the called function only cares about the path to the submodule from the current directory, no?
The second parameter of this call seems totally bogus to me. What is the vocabulary of bits the called function takes? Is that from the same set the flags this function takes? Does the called function even understand OPT_QUIET, or does the bitpattern that happens to correspond to OPT_QUIET have a totally different meaning to the called function and we will trigger a behaviour that this caller does not expect at all?
Thanks.
Apologies for the late reply, I got caught up with other commitments.
Quoted 13 lines · Junio C Hamano
Quoted 1 line · Mugdha Pattnaik via GitGitGadget
From: mugdha <[email protected]>
This line is called "in-body header" that is used to override the author name that is automatically obtained from the e-mail's "From:" header (which is set to "Mugdha Pattnaik via GitGitGadget" by GGG, which is obviously not your name, hence we use an in-body header to override it). It should match what you use to sign off your patches, the one we see below.
Quoted 3 lines
I'll hand-edit so that "git show" will say that the author is "Mugdha Pattnaik", not "mugdha", while applying, but please make sure your further submissions will not have this problem.
Okay, I will keep this in mind for future patches.
Quoted 12 lines
Quoted 4 lines
Currently, running 'git submodule deinit' on repos where the submodule's '.git' is a directory, aborts with a message that is not exactly user friendly. Let's change this to instead warn the user to rerun the command with '--force'.
OK. That sounds like an improvement, albeit possibly an overly cautious one, as a casual "deinit" user will get an error as before without "--force", which may or may not be a good thing. Requiring "--force" means it is safer by default by not changing the on-disk data. But requiring "--force" also means we end up training users to say "--force" when it shouldn't have to be.
Quoted 6 lines
A plausible alternative is to always absorb but with a warning "we absorbed it for you", without requiring "--force". If we didn't have "git submodule deinit" command now and were designing it from scratch, would we design it to fail because the submodule's git directory is not absorbed? I doubt it, as I do not think of a good reason to do so offhand.
Okay, I understand now. I'll remove the condition that checks for "--force" and will go ahead with absorbing the gitdir after displaying the suggested warning message. Currently I suppress the warnings when the "--quiet" flag is set; I think I will continue to do that, even after implementing the above change. Do let me know if I should be doing otherwise.
Quoted 9 lines
Does "git submodule" currently reject a "deinit" request due to some _other_ conditions or safety concerns and require the "--force" option to continue? Requiring the "--force" option to resolve ".git is a directory, and the user wants to make it absorbed" means that the user will be _forced_ to bypass these _other_ safety valves only to save the submodule repository from destruction when running "deinit", which may not be a good trade-off between the safety requirements of these _other_ conditions, if exists, and the one we are dealing with.
This is definitely a situation we want to avoid. How about we try to run a check for uncommitted local modifications first? If these are present, then deinit can die with a warning. In case there are no uncommitted local modifications, deinit can go ahead and absorb the gitdir and do the rest.
The existing submodule--helper.c file already has a check for this, but it seems to be doing it below the check for absorption. I can try to switch it around to see how that works.
Quoted 11 lines
Quoted 4 lines
This internally calls '
absorb_git_dir_into_superproject()', which moves the git dir into the superproject and replaces it with a '.git' file. The rest of the deinit function can operate as it already does with new-style submodules.This is not wrong per-se, but such an implementation detail is something best left for the patch.
Quoted 2 lines
We also edit a test case such that it matches the new behaviour of deinit.
Quoted 8 lines
"match the new behaviour" in what way?
In one test, we used to require "git submodule deinit" to fail even with the "--force" option when the submodule's .git/ directory is not absorbed. Adjust it to expect the operation to pass.
would be a description at the right level of detail, I think.
Noted. I'll apply the above changes.
Quoted 32 lines
Quoted 32 lines
builtin/submodule--helper.c +14
-10@@ -1539,16 +1539,24 @@ static void deinit_submodule(const char *path, const char *prefix,struct strbuf sb_rm =STRBUF_INIT ;const char *format; -/* -* protect submodules containing a .git directory -* NEEDSWORK: instead of dying, automatically call -* absorbgitdirs and (possibly) warn. -*/ -if (is_directory (sub_git_dir)) -die (_ ("Submodule work tree '%s' contains a .git " -"directory (use 'rm -rf' if you really want " -"to remove it including all of its history)" ), - displaypath); +if (is_directory (sub_git_dir)) { +if (!(flags &OPT_FORCE )) +die (_ ("Submodule work tree '%s' contains a " +".git directory.\nUse --force if you want " +"to move its contents to superproject's " +"module directory and convert .git to a file " +"and then proceed with deinit." ), + displaypath); + +if (!(flags &OPT_QUIET )) +warning (_ ("Submodule work tree '%s' contains a .git " +"directory. This will be replaced with a " +".git file by using absorbgitdirs." ), + displaypath);
Quoted 8 lines
builtin/submodule--helper.c static void deinit_submodule(const char *path, const char *prefix, · line 1557
Quoted 2 lines
builtin/submodule--helper.c +2
-0+ +absorb_git_dir_into_superproject (displaypath, flags);Shouldn't the first argument to this call be "path" not "displaypath"? The paths in messages may want to have the path from the top to the submodule location prefixed for human consumption, but the called function only cares about the path to the submodule from the current directory, no?
Yes that makes sense, path is the better argument to pass.
Quoted 7 lines
The second parameter of this call seems totally bogus to me. What is the vocabulary of bits the called function takes? Is that from the same set the flags this function takes? Does the called function even understand
OPT_QUIET, or does the bitpattern that happens to correspond toOPT_QUIEThave a totally different meaning to the called function and we will trigger a behaviour that this caller does not expect at all?
I realised I was passing the wrong flags. On investigating further, the flags in submodule.c do have different semantics. I also noticed that it checks for recursive submodule absorption. I believe I should just be passing the recursive flag to the function that absorbs gitdir. This way, nested old-style gitdirs will also be handled.
I intend to incorporate these changes by the end of the week.
Thanks
--
Mugdha
Quoted 17 lines · Mugdha Pattnaik
Quoted 8 lines
OK. That sounds like an improvement, albeit possibly an overly cautious one, as a casual "deinit" user will get an error as before without "--force", which may or may not be a good thing. Requiring "--force" means it is safer by default by not changing the on-disk data. But requiring "--force" also means we end up training users to say "--force" when it shouldn't have to be.
...
Does "git submodule" currently reject a "deinit" request due to someQuoted 8 lines
_other_ conditions or safety concerns and require the "--force" option to continue? Requiring the "--force" option to resolve ".git is a directory, and the user wants to make it absorbed" means that the user will be _forced_ to bypass these _other_ safety valves only to save the submodule repository from destruction when running "deinit", which may not be a good trade-off between the safety requirements of these _other_ conditions, if exists, and the one we are dealing with.
Quoted 2 lines
This is definitely a situation we want to avoid. How about we try to run a check for uncommitted local modifications first?
I am not sure if I follow. If we stop (ab)using "--force" for the situation (i.e. where today's "deinit" would die because .git needs to be absorbed first), then the user would not have to say "--force" which may override other safety valve. You'd check if .git needs to be absorbed, make it absorbed as needed while reporting the fact that you did so, and then let the existing "deinit" code to take over. If there are other safety checks that needs "--force" to be overridden, that is handled (presumably) correctly by the existing code, no? So other than "do we need absorbing, and if so do it for the user" check, I do not think you'd need to add any new "we try to run a check for ..." at all.
Quoted 23 lines · Junio C Hamano
Quoted 17 lines · Mugdha Pattnaik
Quoted 8 lines
OK. That sounds like an improvement, albeit possibly an overly cautious one, as a casual "deinit" user will get an error as before without "--force", which may or may not be a good thing. Requiring "--force" means it is safer by default by not changing the on-disk data. But requiring "--force" also means we end up training users to say "--force" when it shouldn't have to be.
...
Does "git submodule" currently reject a "deinit" request due to someQuoted 8 lines
_other_ conditions or safety concerns and require the "--force" option to continue? Requiring the "--force" option to resolve ".git is a directory, and the user wants to make it absorbed" means that the user will be _forced_ to bypass these _other_ safety valves only to save the submodule repository from destruction when running "deinit", which may not be a good trade-off between the safety requirements of these _other_ conditions, if exists, and the one we are dealing with.
Quoted 2 lines
This is definitely a situation we want to avoid. How about we try to run a check for uncommitted local modifications first?
Quoted 11 lines
I am not sure if I follow. If we stop (ab)using "--force" for the situation (i.e. where today's "deinit" would die because .git needs to be absorbed first), then the user would not have to say "--force" which may override other safety valve. You'd check if .git needs to be absorbed, make it absorbed as needed while reporting the fact that you did so, and then let the existing "deinit" code to take over. If there are other safety checks that needs "--force" to be overridden, that is handled (presumably) correctly by the existing code, no? So other than "do we need absorbing, and if so do it for the user" check, I do not think you'd need to add any new "we try to run a check for ..." at all.
Yes, I understand why "--force" should not be used. The reason why I suggested the check for local modifications is because I thought we should warn users that they have local modifications before we absorb the gitdir. But I see now that this is okay, considering deinit would die in such a situation anyway, and users would not lose their work. The only side-effect of running deinit despite users having local modifications, would be that the gitdir of the submodule has been absorbed and that should be okay.
Signature · 1 line
Mugdha
PATCH v7 1/1 submodule: absorb git dir instead of dying on deinit
In reply to Mugdha Pattnaik via GitGitGadgetFrom: Mugdha Pattnaik <[email protected]>
Currently, running 'git submodule deinit' on repos where the submodule's '.git' is a directory, aborts with a message that is not exactly user friendly.
Let's change this to instead warn the user that the .git/ directory has been absorbed into the superproject.
The rest of the deinit function can operate as it already does with new-style submodules.
In one test, we used to require "git submodule deinit" to fail even with the "--force" option when the submodule's .git/ directory is not absorbed. Adjust it to expect the operation to pass.
---
submodule: absorb git dir instead of dying on deinit
Changes since v6:
* Edited commit message based on suggestions given.
* Passed correct arguments to absorb gitdir function; path and recurse flag
* Modified behaviour of deinit such that it absorbs the gitdir even when not forced.
Changes since v5:
* Fixed accidental submission of old version
Changes since v4:
* Changed test case from "! test -d" to "test_path_is_missing"
Changes since v3:
* Replaced 1 instance of the word "folder" with "directory"
* Fixed tab spacing
Changes since v2:
* Replaced all instances of the word "folder" with either "directory" or "git dir"
Changes since v1:
* Removed extra indent within the if statements
* Moved absorb_git_dir_into_superproject() call outside the if condition checking for --quiet flag
------------------------------------------------------------------------
Currently, running 'git submodule deinit' on repos where the submodule's '.git' is a directory, aborts with a message that is not exactly user friendly.
Let's change this to instead warn the user that the .git/ directory has been absorbed into the superproject. The rest of the deinit function can operate as it already does with new-style submodules.
In one test, we used to require "git submodule deinit" to fail even with the "--force" option when the submodule's .git/ directory is not absorbed. Adjust it to expect the operation to pass.
I have changed the 'cp -R ../.git/modules/example .git' to 'mv ../.git/modules/example .git' since, at the time of testing, the test would fail - deinit now would be moving the '.git' directory into the superproject's '.git/modules/' directory, and since this same directory already existed before, it was causing errors. So, before running deinit, instead of copying the '.git' directory into the submodule, if we move it there instead, this functionality can be appropriately tested.
Thank you, Mugdha
Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-git-1078%2Fmugdhapattnaik%2Fsubmodule-deinit-absorbgitdirs-v7
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-git-1078/mugdhapattnaik/submodule-deinit-absorbgitdirs-v7
Pull-Request: https://github.com/git/git/pull/1078
Range-diff vs v6:
1: 384a6742388 ! 1: f37724016f0 submodule: absorb git dir instead of dying on deinit
@@
## Metadata ##
-Author: mugdha <[email protected]>
+Author: Mugdha Pattnaik <[email protected]>
## Commit message ##
submodule: absorb git dir instead of dying on deinit
Currently, running 'git submodule deinit' on repos where the submodule's '.git' is a directory, aborts with a message that is not
- exactly user friendly. Let's change this to instead warn the user
- to rerun the command with '--force'.
+ exactly user friendly.
- This internally calls 'absorb_git_dir_into_superproject()', which
- moves the git dir into the superproject and replaces it with
- a '.git' file. The rest of the deinit function can operate as it
- already does with new-style submodules.
+ Let's change this to instead warn the user that the .git/ directory
+ has been absorbed into the superproject.
+ The rest of the deinit function can operate as it already does with
+ new-style submodules.
- We also edit a test case such that it matches the new behaviour of
- deinit.
+ In one test, we used to require "git submodule deinit" to fail even
+ with the "--force" option when the submodule's .git/ directory is not
+ absorbed. Adjust it to expect the operation to pass.
@@ builtin/submodule--helper.c: static void deinit_submodule(const char *path, cons
- "to remove it including all of its history)"),
- displaypath);
+ if (is_directory(sub_git_dir)) {
-+ if (!(flags & OPT_FORCE))
-+ die(_("Submodule work tree '%s' contains a "
-+ ".git directory.\nUse --force if you want "
-+ "to move its contents to superproject's "
-+ "module directory and convert .git to a file "
-+ "and then proceed with deinit."),
-+ displaypath);
-+
+ if (!(flags & OPT_QUIET))
+ warning(_("Submodule work tree '%s' contains a .git "
+ "directory. This will be replaced with a "
+ ".git file by using absorbgitdirs."),
+ displaypath);
+
-+ absorb_git_dir_into_superproject(displaypath, flags);
++ absorb_git_dir_into_superproject(path,
++ ABSORB_GITDIR_RECURSE_SUBMODULES);
+
+ }
@@ t/t7400-submodule-basic.sh: test_expect_success 'submodule deinit is silent when
'
-test_expect_success 'submodule deinit fails when submodule has a .git directory even when forced' '
-+test_expect_success 'submodule deinit fails when submodule has a .git directory unless forced' ' ++test_expect_success 'submodule deinit absorbs .git directory if .git is a directory' '
git submodule update --init &&
(
cd init &&
@@ t/t7400-submodule-basic.sh: test_expect_success 'submodule deinit is silent when
+ mv ../.git/modules/example .git &&
GIT_WORK_TREE=. git config --unset core.worktree
) &&
- test_must_fail git submodule deinit init &&
+- test_must_fail git submodule deinit init &&
- test_must_fail git submodule deinit -f init &&
- test -d init/.git &&
- test -n "$(git config --get-regexp "submodule\.example\.")"
-+ git submodule deinit -f init &&
++ git submodule deinit init &&
+ test_path_is_missing init/.git &&
+ test -z "$(git config --get-regexp "submodule\.example\.")"
'
builtin/submodule--helper.c | 21 +++++++++++---------- t/t7400-submodule-basic.sh | 11 +++++------ 2 files changed, 16 insertions(+), 16 deletions(-)
builtin/submodule--helper.c +11 -10
@@ -1539,16 +1539,17 @@ static void deinit_submodule(const char *path, const char *prefix,struct strbuf sb_rm =STRBUF_INIT ;const char *format; -/* -* protect submodules containing a .git directory -* NEEDSWORK: instead of dying, automatically call -* absorbgitdirs and (possibly) warn. -*/ -if (is_directory (sub_git_dir)) -die (_ ("Submodule work tree '%s' contains a .git " -"directory (use 'rm -rf' if you really want " -"to remove it including all of its history)" ), - displaypath); +if (is_directory (sub_git_dir)) { +if (!(flags &OPT_QUIET )) +warning (_ ("Submodule work tree '%s' contains a .git " +"directory. This will be replaced with a " +".git file by using absorbgitdirs." ), + displaypath); + +absorb_git_dir_into_superproject (path, +ABSORB_GITDIR_RECURSE_SUBMODULES ); + + }if (!(flags &OPT_FORCE )) {struct child_process cp_rm =CHILD_PROCESS_INIT ;
t/t7400-submodule-basic.sh +5 -6
@@ -1182,18 +1182,17 @@ test_expect_success 'submodule deinit is silent when used on an uninitialized su rmdir init example2 ' -test_expect_success 'submodule deinit fails when submodule has a .git directory even when forced' ' +test_expect_success 'submodule deinit absorbs .git directory if .git is a directory' ' git submodule update --init && ( cd init && rm .git && - cp -R ../.git/modules/example .git && + mv ../.git/modules/example .git && GIT_WORK_TREE=. git config --unset core.worktree ) && - test_must_fail git submodule deinit init && - test_must_fail git submodule deinit -f init && - test -d init/.git && - test -n "$(git config --get-regexp "submodule\.example\.")" + git submodule deinit init && + test_path_is_missing init/.git && + test -z "$(git config --get-regexp "submodule\.example\.")" ' test_expect_success 'submodule with UTF-8 name' '
base-commit: c4203212e360b25a1c69467b5a8437d45a373cac
Signature · 1 line
gitgitgadget