submodule output patches
cover submodule output patches
Patch 1 was send outside of a series already.
Patch 2 and 3 are preparatory things for the submodule groups stuff
patches 4-9 are making the output of the submodule command consistent (similar to patch 3, but I do not foresee a need for it yet)
Patch 10 is a controversial thing I'd assume as it breaks existing users. We should take it for the next major release (i.e. 3.0)
I just want to put it out here now.
Thanks,
Stefan
Stefan Beller (10):
submodule deinit test: fix broken && chain in subshell submodule deinit: lose requirement for giving '.' submodule init: redirect stdout to stderr
shell helpers usage: always send help to stderr submodule add: send messages to stderr
submodule deinit: send messages to stderr
submodule foreach: send messages to stderr
submodule update: send messages to stderr
submodule sync: send messages to stderr
submodule deinit: complain when given a file instead of a submodule
builtin/submodule--helper.c | 9 +++++---- git-sh-setup.sh | 2 +- git-submodule.sh | 21 ++++++++------------- t/t7400-submodule-basic.sh | 38 +++++++++++++++++++++++++------------- t/t7403-submodule-sync.sh | 4 ++-- t/t7406-submodule-update.sh | 23 ++++++++++++++++------- t/t7407-submodule-foreach.sh | 35 ++++++++++++++++++++++------------- 7 files changed, 79 insertions(+), 53 deletions(-)
Signature · 1 line
2.8.0.32.g71f8beb.dirty
PATCH 1/10 submodule deinit test: fix broken && chain in subshell
--- t/t7400-submodule-basic.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
t/t7400-submodule-basic.sh +1 -1
@@ -914,7 +914,7 @@ test_expect_success 'submodule deinit works on repository without submodules' ' git init && >file && git add file && - git commit -m "repo should not be empty" + git commit -m "repo should not be empty" && git submodule deinit . ) '
Signature · 1 line
2.8.0.32.g71f8beb.dirty
PATCH 2/10 submodule deinit: lose requirement for giving '.'
In reply to Stefan BellerThe discussion in [1] realized that '.' is a faulty suggestion as there is a corner case where it fails:
Quoted 5 lines
"submodule deinit ." may have "worked" in the sense that you would have at least one path in your tree and avoided this "nothing matches" most of the time. It would have still failed with the exactly same error if run in an empty repository, i.e.
Quoted 9 lines
$ E=/var/tmp/x/empty && rm -fr "$E" && mkdir -p "$E" && cd "$E"
$ git init
$ rungit v2.6.6 submodule deinit .
error: pathspec '.' did not match any file(s) known to git.
Did you forget to 'git add'?
$ >file && git add file
$ rungit v2.6.6 submodule deinit .
$ echo $?
0There is no need to update the documentation as it did not describe the special case '.' to remove all submodules.
[1] http://news.gmane.org/gmane.comp.version-control.git/289535
--- git-submodule.sh | 5 ----- t/t7400-submodule-basic.sh | 1 - 2 files changed, 6 deletions(-)
git-submodule.sh +0 -5
@@ -428,11 +428,6 @@ cmd_deinit() shift done - if test $# = 0 - then - die "$(eval_gettext "Use '.' if you really want to deinitialize all submodules")" - fi - git submodule--helper list --prefix "$wt_prefix" "$@" | while read mode sha1 stage sm_path do
t/t7400-submodule-basic.sh +0 -1
@@ -948,7 +948,6 @@ test_expect_success 'submodule deinit . deinits all initialized submodules' ' git submodule update --init && git config submodule.example.foo bar && git config submodule.example2.frotz nitfol && - test_must_fail git submodule deinit && git submodule deinit . >actual && test -z "$(git config --get-regexp "submodule\.example\.")" && test -z "$(git config --get-regexp "submodule\.example2\.")" &&
Signature · 1 line
2.8.0.32.g71f8beb.dirty
PATCH 3/10 submodule init: redirect stdout to stderr
In reply to Stefan BellerReroute the output of stdout to stderr as it is just informative messages, not to be consumed by machines.
We want to init submodules from the helper for submodule update in a later patch and the stdout output of said helper is consumed by the parts of submodule update which are still written in shell. So we have to be careful which messages are on stdout.
--- builtin/submodule--helper.c | 3 ++- t/t7406-submodule-update.sh | 24 ++++++++++++++++++------ 2 files changed, 20 insertions(+), 7 deletions(-)
builtin/submodule--helper.c +2 -1
@@ -366,7 +366,8 @@ static void init_submodule(const char *path, const char *prefix, int quiet)die (_ ("Failed to register url for submodule path '%s'" ), displaypath);if (!quiet) -printf (_ ("Submodule '%s' (%s) registered for path '%s'\n" ), +fprintf (stderr, +_ ("Submodule '%s' (%s) registered for path '%s'\n" ), sub->name, url, displaypath); }
t/t7406-submodule-update.sh +18 -6
@@ -108,24 +108,36 @@ pwd=$(pwd) cat <<EOF >expect Submodule path '../super': checked out '$supersha1' -Submodule 'merging' ($pwd/merging) registered for path '../super/merging' -Submodule 'none' ($pwd/none) registered for path '../super/none' -Submodule 'rebasing' ($pwd/rebasing) registered for path '../super/rebasing' -Submodule 'submodule' ($pwd/submodule) registered for path '../super/submodule' Submodule path '../super/merging': checked out '$mergingsha1' Submodule path '../super/none': checked out '$nonesha1' Submodule path '../super/rebasing': checked out '$rebasingsha1' Submodule path '../super/submodule': checked out '$submodulesha1' EOF +cat <<EOF >expect2 +Submodule 'merging' ($pwd/merging) registered for path '../super/merging' +Submodule 'none' ($pwd/none) registered for path '../super/none' +Submodule 'rebasing' ($pwd/rebasing) registered for path '../super/rebasing' +Submodule 'submodule' ($pwd/submodule) registered for path '../super/submodule' +Cloning into '$pwd/recursivesuper/super/merging'... +done. +Cloning into '$pwd/recursivesuper/super/none'... +done. +Cloning into '$pwd/recursivesuper/super/rebasing'... +done. +Cloning into '$pwd/recursivesuper/super/submodule'... +done. +EOF + test_expect_success 'submodule update --init --recursive from subdirectory' ' git -C recursivesuper/super reset --hard HEAD^ && (cd recursivesuper && mkdir tmp && cd tmp && - git submodule update --init --recursive ../super >../../actual + git submodule update --init --recursive ../super >../../actual 2>../../actual2 ) && - test_cmp expect actual + test_cmp expect actual && + test_cmp expect2 actual2 ' apos="'";
Signature · 1 line
2.8.0.32.g71f8beb.dirty
PATCH 4/10 shell helpers usage: always send help to stderr
In reply to Stefan Bellergit submodule asdf would trigger displaying the usage of the submodule command on stderr, however git submodule -h would display the usage on stdout. Unify displaying help for shell commands on stderr.
--- git-sh-setup.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
git-sh-setup.sh +1 -1
@@ -65,7 +65,7 @@ say () { if test -n "$OPTIONS_SPEC"; then usage() { - "$0" -h + "$0" -h 1>&2 exit 1 }
Signature · 1 line
2.8.0.32.g71f8beb.dirty
Re: [PATCH 04/10] shell helpers usage: always send help to stderr
Quoted 3 lines · Stefan Beller
git submodule asdfwould trigger displaying the usage of the submodule command on stderr, howevergit submodule -hwould display the usage on stdout. Unify displaying help for shell commands on stderr.
The primary output from "git cmd --help" is the usage message. It is debatable why it should go to the standard error output when it is the primary thing the user asked for.
Quoted 18 lines
Signed-off-by Stefan Beller <[email protected]>--- git-sh-setup.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)git-sh-setup.sh +1
-1@@ -65,7 +65,7 @@ say () { if test -n "$OPTIONS_SPEC"; then usage() { - "$0" -h + "$0" -h 1>&2 exit 1 }
Re: [PATCH 04/10] shell helpers usage: always send help to stderr
Quoted 9 lines · Junio C Hamano
Quoted 3 lines · Stefan Beller
git submodule asdfwould trigger displaying the usage of the submodule command on stderr, howevergit submodule -hwould display the usage on stdout. Unify displaying help for shell commands on stderr.The primary output from "git cmd --help" is the usage message. It is debatable why it should go to the standard error output when it is the primary thing the user asked for.
I had written some lengthy arguments, but when I wanted to back up with data and facts, the first search result[1] convinced me this is a bad patch as when a user asks for help specifically, they want it to easily be piped, i.e.
git --help |grep pull
instead of
git --help 2>&1 |grep pull
So I'll drop this patch.
Thanks,
Stefan
[1] http://www.jstorimer.com/blogs/workingwithcode/7766119-when-to-use-stderr-instead-of-stdout
Quoted 21 lines
Quoted 21 lines
Signed-off-by Stefan Beller <[email protected]>--- git-sh-setup.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)git-sh-setup.sh +1
-1@@ -65,7 +65,7 @@ say () { if test -n "$OPTIONS_SPEC"; then usage() { - "$0" -h + "$0" -h 1>&2 exit 1 }
Re: [PATCH 04/10] shell helpers usage: always send help to stderr
Quoted 5 lines · Stefan Beller
git --help |grep pullinstead of
git --help 2>&1 |grep pull
Not just that. It makes me sad that it is unpredictable which stream a project happens to have chosen to send its help text and I end up almost always doing
random-command --help 2>&1 | less
Re: [PATCH 04/10] shell helpers usage: always send help to stderr
It also is somewhat sad that you needed to refer to a random blog you found on the Internet whose punch line was essentially what I already said before you finally decide to listen to me X-<. I somehow expected that over the years you worked with me you learned I had a reasonable taste in designing these things...
Quoted 14 lines · Junio C Hamano
Quoted 5 lines · Stefan Beller
git --help |grep pullinstead of
git --help 2>&1 |grep pullNot just that. It makes me sad that it is unpredictable which stream a project happens to have chosen to send its help text and I end up almost always doing
random-command --help 2>&1 | less
PATCH 5/10 submodule add: send messages to stderr
In reply to Stefan BellerReroute the output of stdout to stderr as it is just informative messages, not to be consumed by machines.
This should not regress any scripts that try to parse the current output, as the output is already internationalized and therefore unstable.
--- git-submodule.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
git-submodule.sh +1 -1
@@ -271,7 +271,7 @@ Use -f if you really want to add it." >&2 echo >&2 "$(eval_gettext "use the '--force' option. If the local git directory is not the correct repo")" die "$(eval_gettext "or you are unsure what this means choose another name with the '--name' option.")" else - echo "$(eval_gettext "Reactivating local git directory for submodule '\$sm_name'.")" + echo >&2 "$(eval_gettext "Reactivating local git directory for submodule '\$sm_name'.")" fi fi git submodule--helper clone ${GIT_QUIET:+--quiet} --prefix "$wt_prefix" --path "$sm_path" --name "$sm_name" --url "$realrepo" "$reference" "$depth" || exit
Signature · 1 line
2.8.0.32.g71f8beb.dirty
Re: [PATCH 05/10] submodule add: send messages to stderr
Quoted 9 lines · Stefan Beller
Reroute the output of stdout to stderr as it is just informative messages, not to be consumed by machines.
This should not regress any scripts that try to parse the current output, as the output is already internationalized and therefore unstable.
Signed-off-by Stefan Beller <[email protected]>---
Sounds sensible.
Quoted 16 lines
git-submodule.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)git-submodule.sh +1
-1@@ -271,7 +271,7 @@ Use -f if you really want to add it." >&2 echo >&2 "$(eval_gettext "use the '--force' option. If the local git directory is not the correct repo")" die "$(eval_gettext "or you are unsure what this means choose another name with the '--name' option.")" else - echo "$(eval_gettext "Reactivating local git directory for submodule '\$sm_name'.")" + echo >&2 "$(eval_gettext "Reactivating local git directory for submodule '\$sm_name'.")" fi fi git submodule--helper clone ${GIT_QUIET:+--quiet} --prefix "$wt_prefix" --path "$sm_path" --name "$sm_name" --url "$realrepo" "$reference" "$depth" || exit
PATCH 6/10 submodule deinit: send messages to stderr
In reply to Stefan BellerReroute the output of stdout to stderr as it is just informative messages, not to be consumed by machines.
This should not regress any scripts that try to parse the current output, as the output is already internationalized and therefore unstable.
--- git-submodule.sh | 8 ++++---- t/t7400-submodule-basic.sh | 20 ++++++++++---------- 2 files changed, 14 insertions(+), 14 deletions(-)
git-submodule.sh +4 -4
@@ -452,11 +452,11 @@ cmd_deinit() die "$(eval_gettext "Submodule work tree '\$displaypath' contains local modifications; use '-f' to discard them")" fi rm -rf "$sm_path" && - say "$(eval_gettext "Cleared directory '\$displaypath'")" || - say "$(eval_gettext "Could not remove submodule work tree '\$displaypath'")" + say >&2 "$(eval_gettext "Cleared directory '\$displaypath'")" || + say >&2 "$(eval_gettext "Could not remove submodule work tree '\$displaypath'")" fi - mkdir "$sm_path" || say "$(eval_gettext "Could not create empty submodule directory '\$displaypath'")" + mkdir "$sm_path" || say >&2 "$(eval_gettext "Could not create empty submodule directory '\$displaypath'")" # Remove the .git/config entries (unless the user already did it) if test -n "$(git config --get-regexp submodule."$name\.")"
@@ -465,7 +465,7 @@ cmd_deinit() # the user later decides to init this submodule again url=$(git config submodule."$name".url) git config --remove-section submodule."$name" 2>/dev/null && - say "$(eval_gettext "Submodule '\$name' (\$url) unregistered for path '\$displaypath'")" + say >&2 "$(eval_gettext "Submodule '\$name' (\$url) unregistered for path '\$displaypath'")" fi done }
t/t7400-submodule-basic.sh +10 -10
@@ -935,7 +935,7 @@ test_expect_success 'submodule deinit from subdirectory' ' mkdir -p sub && ( cd sub && - git submodule deinit ../init >../output + git submodule deinit ../init 2>../output ) && grep "\\.\\./init" output && test -z "$(git config --get-regexp "submodule\.example\.")" &&
@@ -948,7 +948,7 @@ test_expect_success 'submodule deinit . deinits all initialized submodules' ' git submodule update --init && git config submodule.example.foo bar && git config submodule.example2.frotz nitfol && - git submodule deinit . >actual && + git submodule deinit . 2>actual && test -z "$(git config --get-regexp "submodule\.example\.")" && test -z "$(git config --get-regexp "submodule\.example2\.")" && test_i18ngrep "Cleared directory .init" actual &&
@@ -959,7 +959,7 @@ test_expect_success 'submodule deinit . deinits all initialized submodules' ' test_expect_success 'submodule deinit deinits a submodule when its work tree is missing or empty' ' git submodule update --init && rm -rf init example2/* example2/.git && - git submodule deinit init example2 >actual && + git submodule deinit init example2 2>actual && test -z "$(git config --get-regexp "submodule\.example\.")" && test -z "$(git config --get-regexp "submodule\.example2\.")" && test_i18ngrep ! "Cleared directory .init" actual &&
@@ -973,7 +973,7 @@ test_expect_success 'submodule deinit fails when the submodule contains modifica test_must_fail git submodule deinit init && test -n "$(git config --get-regexp "submodule\.example\.")" && test -f example2/.git && - git submodule deinit -f init >actual && + git submodule deinit -f init 2>actual && test -z "$(git config --get-regexp "submodule\.example\.")" && test_i18ngrep "Cleared directory .init" actual && rmdir init
@@ -985,7 +985,7 @@ test_expect_success 'submodule deinit fails when the submodule contains untracke test_must_fail git submodule deinit init && test -n "$(git config --get-regexp "submodule\.example\.")" && test -f example2/.git && - git submodule deinit -f init >actual && + git submodule deinit -f init 2>actual && test -z "$(git config --get-regexp "submodule\.example\.")" && test_i18ngrep "Cleared directory .init" actual && rmdir init
@@ -1000,7 +1000,7 @@ test_expect_success 'submodule deinit fails when the submodule HEAD does not mat test_must_fail git submodule deinit init && test -n "$(git config --get-regexp "submodule\.example\.")" && test -f example2/.git && - git submodule deinit -f init >actual && + git submodule deinit -f init 2>actual && test -z "$(git config --get-regexp "submodule\.example\.")" && test_i18ngrep "Cleared directory .init" actual && rmdir init
@@ -1008,17 +1008,17 @@ test_expect_success 'submodule deinit fails when the submodule HEAD does not mat test_expect_success 'submodule deinit is silent when used on an uninitialized submodule' ' git submodule update --init && - git submodule deinit init >actual && + git submodule deinit init 2>actual && test_i18ngrep "Submodule .example. (.*) unregistered for path .init" actual && test_i18ngrep "Cleared directory .init" actual && - git submodule deinit init >actual && + git submodule deinit init 2>actual && test_i18ngrep ! "Submodule .example. (.*) unregistered for path .init" actual && test_i18ngrep "Cleared directory .init" actual && - git submodule deinit . >actual && + git submodule deinit . 2>actual && test_i18ngrep ! "Submodule .example. (.*) unregistered for path .init" actual && test_i18ngrep "Submodule .example2. (.*) unregistered for path .example2" actual && test_i18ngrep "Cleared directory .init" actual && - git submodule deinit . >actual && + git submodule deinit . 2>actual && test_i18ngrep ! "Submodule .example. (.*) unregistered for path .init" actual && test_i18ngrep ! "Submodule .example2. (.*) unregistered for path .example2" actual && test_i18ngrep "Cleared directory .init" actual &&
Signature · 1 line
2.8.0.32.g71f8beb.dirty
Re: [PATCH 06/10] submodule deinit: send messages to stderr
Quoted 9 lines · Stefan Beller
Reroute the output of stdout to stderr as it is just informative messages, not to be consumed by machines.
This should not regress any scripts that try to parse the current output, as the output is already internationalized and therefore unstable.
Signed-off-by Stefan Beller <[email protected]>---
Sounds sensible.
Quoted 112 lines
git-submodule.sh | 8 ++++---- t/t7400-submodule-basic.sh | 20 ++++++++++---------- 2 files changed, 14 insertions(+), 14 deletions(-)git-submodule.sh +4
-4@@ -452,11 +452,11 @@ cmd_deinit() die "$(eval_gettext "Submodule work tree '\$displaypath' contains local modifications; use '-f' to discard them")" fi rm -rf "$sm_path" && - say "$(eval_gettext "Cleared directory '\$displaypath'")" || - say "$(eval_gettext "Could not remove submodule work tree '\$displaypath'")" + say >&2 "$(eval_gettext "Cleared directory '\$displaypath'")" || + say >&2 "$(eval_gettext "Could not remove submodule work tree '\$displaypath'")" fi - mkdir "$sm_path" || say "$(eval_gettext "Could not create empty submodule directory '\$displaypath'")" + mkdir "$sm_path" || say >&2 "$(eval_gettext "Could not create empty submodule directory '\$displaypath'")" # Remove the .git/config entries (unless the user already did it) if test -n "$(git config --get-regexp submodule."$name\.")"@@ -465,7 +465,7 @@ cmd_deinit() # the user later decides to init this submodule again url=$(git config submodule."$name".url) git config --remove-section submodule."$name" 2>/dev/null && - say "$(eval_gettext "Submodule '\$name' (\$url) unregistered for path '\$displaypath'")" + say >&2 "$(eval_gettext "Submodule '\$name' (\$url) unregistered for path '\$displaypath'")" fi done }t/t7400-submodule-basic.sh +10
-10@@ -935,7 +935,7 @@ test_expect_success 'submodule deinit from subdirectory' ' mkdir -p sub && ( cd sub && - git submodule deinit ../init >../output + git submodule deinit ../init 2>../output ) && grep "\\.\\./init" output && test -z "$(git config --get-regexp "submodule\.example\.")" &&@@ -948,7 +948,7 @@ test_expect_success 'submodule deinit . deinits all initialized submodules' ' git submodule update --init && git config submodule.example.foo bar && git config submodule.example2.frotz nitfol && - git submodule deinit . >actual && + git submodule deinit . 2>actual && test -z "$(git config --get-regexp "submodule\.example\.")" && test -z "$(git config --get-regexp "submodule\.example2\.")" && test_i18ngrep "Cleared directory .init" actual &&@@ -959,7 +959,7 @@ test_expect_success 'submodule deinit . deinits all initialized submodules' ' test_expect_success 'submodule deinit deinits a submodule when its work tree is missing or empty' ' git submodule update --init && rm -rf init example2/* example2/.git && - git submodule deinit init example2 >actual && + git submodule deinit init example2 2>actual && test -z "$(git config --get-regexp "submodule\.example\.")" && test -z "$(git config --get-regexp "submodule\.example2\.")" && test_i18ngrep ! "Cleared directory .init" actual &&@@ -973,7 +973,7 @@ test_expect_success 'submodule deinit fails when the submodule contains modifica test_must_fail git submodule deinit init && test -n "$(git config --get-regexp "submodule\.example\.")" && test -f example2/.git && - git submodule deinit -f init >actual && + git submodule deinit -f init 2>actual && test -z "$(git config --get-regexp "submodule\.example\.")" && test_i18ngrep "Cleared directory .init" actual && rmdir init@@ -985,7 +985,7 @@ test_expect_success 'submodule deinit fails when the submodule contains untracke test_must_fail git submodule deinit init && test -n "$(git config --get-regexp "submodule\.example\.")" && test -f example2/.git && - git submodule deinit -f init >actual && + git submodule deinit -f init 2>actual && test -z "$(git config --get-regexp "submodule\.example\.")" && test_i18ngrep "Cleared directory .init" actual && rmdir init@@ -1000,7 +1000,7 @@ test_expect_success 'submodule deinit fails when the submodule HEAD does not mat test_must_fail git submodule deinit init && test -n "$(git config --get-regexp "submodule\.example\.")" && test -f example2/.git && - git submodule deinit -f init >actual && + git submodule deinit -f init 2>actual && test -z "$(git config --get-regexp "submodule\.example\.")" && test_i18ngrep "Cleared directory .init" actual && rmdir init@@ -1008,17 +1008,17 @@ test_expect_success 'submodule deinit fails when the submodule HEAD does not mat test_expect_success 'submodule deinit is silent when used on an uninitialized submodule' ' git submodule update --init && - git submodule deinit init >actual && + git submodule deinit init 2>actual && test_i18ngrep "Submodule .example. (.*) unregistered for path .init" actual && test_i18ngrep "Cleared directory .init" actual && - git submodule deinit init >actual && + git submodule deinit init 2>actual && test_i18ngrep ! "Submodule .example. (.*) unregistered for path .init" actual && test_i18ngrep "Cleared directory .init" actual && - git submodule deinit . >actual && + git submodule deinit . 2>actual && test_i18ngrep ! "Submodule .example. (.*) unregistered for path .init" actual && test_i18ngrep "Submodule .example2. (.*) unregistered for path .example2" actual && test_i18ngrep "Cleared directory .init" actual && - git submodule deinit . >actual && + git submodule deinit . 2>actual && test_i18ngrep ! "Submodule .example. (.*) unregistered for path .init" actual && test_i18ngrep ! "Submodule .example2. (.*) unregistered for path .example2" actual && test_i18ngrep "Cleared directory .init" actual &&
PATCH 7/10 submodule foreach: send messages to stderr
In reply to Stefan BellerReroute the output of stdout to stderr as it is just informative messages, not to be consumed by machines.
This should not regress any scripts that try to parse the current output, as the output is already internationalized and therefore unstable.
--- git-submodule.sh | 2 +- t/t7407-submodule-foreach.sh | 35 ++++++++++++++++++++++------------- 2 files changed, 23 insertions(+), 14 deletions(-)
git-submodule.sh +1 -1
@@ -341,7 +341,7 @@ cmd_foreach() if test -e "$sm_path"/.git then displaypath=$(relative_path "$prefix$sm_path") - say "$(eval_gettext "Entering '\$displaypath'")" + say >&2 "$(eval_gettext "Entering '\$displaypath'")" name=$(git submodule--helper name "$sm_path") ( prefix="$prefix$sm_path/"
t/t7407-submodule-foreach.sh +22 -13
@@ -61,29 +61,36 @@ sub3sha1=$(cd super/sub3 && git rev-parse HEAD) pwd=$(pwd) -cat > expect <<EOF -Entering 'sub1' +cat >expect <<EOF $pwd/clone-foo1-sub1-$sub1sha1 -Entering 'sub3' $pwd/clone-foo3-sub3-$sub3sha1 EOF +cat >expect2 <<EOF +Entering 'sub1' +Entering 'sub3' +EOF + test_expect_success 'test basic "submodule foreach" usage' ' git clone super clone && ( cd clone && git submodule update --init -- sub1 sub3 && - git submodule foreach "echo \$toplevel-\$name-\$path-\$sha1" > ../actual && + git submodule foreach "echo \$toplevel-\$name-\$path-\$sha1" >../actual 2>../actual2 && git config foo.bar zar && git submodule foreach "git config --file \"\$toplevel/.git/config\" foo.bar" ) && - test_i18ncmp expect actual + test_i18ncmp expect actual && + test_i18ncmp expect2 actual2 ' -cat >expect <<EOF +cat >expect2 <<EOF Entering '../sub1' -$pwd/clone-foo1-../sub1-$sub1sha1 Entering '../sub3' +EOF + +cat >expect <<EOF +$pwd/clone-foo1-../sub1-$sub1sha1 $pwd/clone-foo3-../sub3-$sub3sha1 EOF
@@ -91,9 +98,10 @@ test_expect_success 'test "submodule foreach" from subdirectory' ' mkdir clone/sub && ( cd clone/sub && - git submodule foreach "echo \$toplevel-\$name-\$sm_path-\$sha1" >../../actual + git submodule foreach "echo \$toplevel-\$name-\$sm_path-\$sha1" >../../actual 2>../../actual2 ) && - test_i18ncmp expect actual + test_i18ncmp expect actual && + test_i18ncmp expect2 actual2 ' test_expect_success 'setup nested submodules' '
@@ -172,7 +180,7 @@ EOF test_expect_success 'test messages from "foreach --recursive"' ' ( cd clone2 && - git submodule foreach --recursive "true" > ../actual + git submodule foreach --recursive "true" 2>../actual ) && test_i18ncmp expect actual '
@@ -192,7 +200,7 @@ test_expect_success 'test messages from "foreach --recursive" from subdirectory' cd clone2 && mkdir untracked && cd untracked && - git submodule foreach --recursive >../../actual + git submodule foreach --recursive 2>../../actual ) && test_i18ncmp expect actual '
@@ -210,9 +218,10 @@ EOF test_expect_success 'test "foreach --quiet --recursive"' ' ( cd clone2 && - git submodule foreach -q --recursive "echo \$name-\$path" > ../actual + git submodule foreach -q --recursive "echo \$name-\$path" >../actual 2> ../actual2 ) && - test_cmp expect actual + test_cmp expect actual && + test_must_be_empty actual2 ' test_expect_success 'use "update --recursive" to checkout all submodules' '
Signature · 1 line
2.8.0.32.g71f8beb.dirty
PATCH 8/10 submodule update: send messages to stderr
In reply to Stefan BellerReroute the output of stdout to stderr as it is just informative messages, not to be consumed by machines.
This should not regress any scripts that try to parse the current output, as the output is already internationalized and therefore unstable.
--- git-submodule.sh | 2 +- t/t7406-submodule-update.sh | 23 ++++++++++------------- 2 files changed, 11 insertions(+), 14 deletions(-)
git-submodule.sh +1 -1
@@ -679,7 +679,7 @@ cmd_update() if (clear_local_git_env; cd "$sm_path" && $command "$sha1") then - say "$say_msg" + say >&2 "$say_msg" elif test -n "$must_die_on_failure" then die_with_status 2 "$die_msg"
t/t7406-submodule-update.sh +10 -13
@@ -106,15 +106,8 @@ rebasingsha1=$(git -C super/rebasing rev-parse HEAD) submodulesha1=$(git -C super/submodule rev-parse HEAD) pwd=$(pwd) -cat <<EOF >expect -Submodule path '../super': checked out '$supersha1' -Submodule path '../super/merging': checked out '$mergingsha1' -Submodule path '../super/none': checked out '$nonesha1' -Submodule path '../super/rebasing': checked out '$rebasingsha1' -Submodule path '../super/submodule': checked out '$submodulesha1' -EOF - cat <<EOF >expect2 +Submodule path '../super': checked out '$supersha1' Submodule 'merging' ($pwd/merging) registered for path '../super/merging' Submodule 'none' ($pwd/none) registered for path '../super/none' Submodule 'rebasing' ($pwd/rebasing) registered for path '../super/rebasing'
@@ -127,6 +120,10 @@ Cloning into '$pwd/recursivesuper/super/rebasing'... done. Cloning into '$pwd/recursivesuper/super/submodule'... done. +Submodule path '../super/merging': checked out '$mergingsha1' +Submodule path '../super/none': checked out '$nonesha1' +Submodule path '../super/rebasing': checked out '$rebasingsha1' +Submodule path '../super/submodule': checked out '$submodulesha1' EOF test_expect_success 'submodule update --init --recursive from subdirectory' '
@@ -136,7 +133,7 @@ test_expect_success 'submodule update --init --recursive from subdirectory' ' cd tmp && git submodule update --init --recursive ../super >../../actual 2>../../actual2 ) && - test_cmp expect actual && + test_must_be_empty actual && test_cmp expect2 actual2 '
@@ -156,8 +153,8 @@ test_expect_success 'submodule update does not fetch already present commits' ' (cd super && git submodule update > ../actual 2> ../actual.err ) && - test_i18ncmp expected actual && - ! test -s actual.err + test_must_be_empty actual && + test_i18ncmp expected actual.err ' test_expect_success 'submodule update should fail due to local changes' '
@@ -790,7 +787,7 @@ test_expect_success 'submodule update places git-dir in superprojects git-dir re rm -rf super_update_r2 && git clone super_update_r super_update_r2 && (cd super_update_r2 && - git submodule update --init --recursive >actual && + git submodule update --init --recursive 2>actual && test_i18ngrep "Submodule path .submodule/subsubmodule.: checked out" actual && (cd submodule/subsubmodule && git log > ../../expected
@@ -858,7 +855,7 @@ test_expect_success 'submodule update --recursive drops module name before recur (cd deeper/submodule/subsubmodule && git checkout HEAD^ ) && - git submodule update --recursive deeper/submodule >actual && + git submodule update --recursive deeper/submodule 2>actual && test_i18ngrep "Submodule path .deeper/submodule/subsubmodule.: checked out" actual ) '
Signature · 1 line
2.8.0.32.g71f8beb.dirty
PATCH 9/10 submodule sync: send messages to stderr
In reply to Stefan BellerReroute the output of stdout to stderr as it is just informative messages, not to be consumed by machines.
This should not regress any scripts that try to parse the current output, as the output is already internationalized and therefore unstable.
--- git-submodule.sh | 2 +- t/t7403-submodule-sync.sh | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-)
git-submodule.sh +1 -1
@@ -1095,7 +1095,7 @@ cmd_sync() if git config "submodule.$name.url" >/dev/null 2>/dev/null then displaypath=$(relative_path "$prefix$sm_path") - say "$(eval_gettext "Synchronizing submodule url for '\$displaypath'")" + say >&2 "$(eval_gettext "Synchronizing submodule url for '\$displaypath'")" git config submodule."$name".url "$super_config_url" if test -e "$sm_path"/.git
t/t7403-submodule-sync.sh +2 -2
@@ -155,7 +155,7 @@ test_expect_success '"git submodule sync" should update submodule URLs - subdire git pull --no-recurse-submodules && mkdir -p sub && cd sub && - git submodule sync >../../output + git submodule sync 2>../../output ) && grep "\\.\\./submodule" output && test -d "$(
@@ -186,7 +186,7 @@ test_expect_success '"git submodule sync --recursive" should update all submodul ) && mkdir -p sub && cd sub && - git submodule sync --recursive >../../output + git submodule sync --recursive 2>../../output ) && grep "\\.\\./submodule/sub-submodule" output && test -d "$(
Signature · 1 line
2.8.0.32.g71f8beb.dirty
PATCH 10/10 submodule deinit: complain when given a file instead of a submodule
In reply to Stefan BellerThis also improves performance for listing submodules, because S_ISGITLINK is both faster as match_pathspec as well as expected to be true in fewer cases, so putting it first in the condition will speed up the loop to compute all submodules.
As this partially reverts 84ba959bbdf0 (submodule: fix regression for deinit without submodules, 2016-03-22), this also disallows the use of git submodule deinit . to deinit all submodules, when no submodules are present. deinit . continues to work on repositories, which have at least one submodule.
---
Quoted 3 lines
Patch 10 is a controversial thing I'd assume as it breaks existing users. We should take it for the next major release (i.e. 3.0)
I just want to put it out here now.
builtin/submodule--helper.c | 6 +++--- t/t7400-submodule-basic.sh | 15 ++++++++++++++- 2 files changed, 17 insertions(+), 4 deletions(-)
builtin/submodule--helper.c +3 -3
@@ -242,9 +242,9 @@ static int module_list_compute(int argc, const char **argv,for (i =0 ; i < active_nr; i++) {const struct cache_entry *ce = active_cache[i]; -if (!match_pathspec (pathspec, ce->name,ce_namelen (ce), -0 , ps_matched,1 ) || - !S_ISGITLINK (ce->ce_mode)) +if (!S_ISGITLINK (ce->ce_mode) || + !match_pathspec (pathspec, ce->name,ce_namelen (ce), +0 , ps_matched,1 ))continue ;ALLOC_GROW (list->entries, list->nr +1 , list->alloc);
t/t7400-submodule-basic.sh +14 -1
@@ -915,7 +915,20 @@ test_expect_success 'submodule deinit works on repository without submodules' ' >file && git add file && git commit -m "repo should not be empty" && - git submodule deinit . + git submodule deinit + ) +' + +test_expect_success 'submodule deinit refuses to deinit a file' ' + test_when_finished "rm -rf newdirectory" && + mkdir newdirectory && + ( + cd newdirectory && + git init && + >file && + git add file && + git commit -m "repo should not be empty" && + test_must_fail git submodule deinit file ) '
Signature · 1 line
2.8.0.32.g71f8beb.dirty
Re: [PATCH 10/10] submodule deinit: complain when given a file instead of a submodule
After this change, what is the simplest way to programmatically deinit any submodule that may exist, without failing if there are none?
"git commit" by default refuses to make an empty commit, but it has the --allow-empty option.
"git rm -r ." by default fails if there are no files in the repository, but it has the --ignore-unmatch option.
It makes sense that "git submodule deinit ." should fail if there are no submodules, but please add support for --ignore-unmatch at the same time.
/ceder
Quoted 70 lines · Stefan Beller
This also improves performance for listing submodules, because
S_ISGITLINKis both faster asmatch_pathspecas well as expected to be true in fewer cases, so putting it first in the condition will speed up the loop to compute all submodules.As this partially reverts
84ba959bbdf0(submodule: fix regression for deinit without submodules, 2016-03-22), this also disallows the use ofgit submodule deinit .to deinit all submodules, when no submodules are present.deinit .continues to work on repositories, which have at least one submodule.CC Per Cederqvist <[email protected]>Signed-off-by Stefan Beller <[email protected]>---
Quoted 3 lines
Patch 10 is a controversial thing I'd assume as it breaks existing users. We should take it for the next major release (i.e. 3.0)
I just want to put it out here now.builtin/submodule--helper.c | 6 +++--- t/t7400-submodule-basic.sh | 15 ++++++++++++++- 2 files changed, 17 insertions(+), 4 deletions(-)builtin/submodule--helper.c +3
-3@@ -242,9 +242,9 @@ static int module_list_compute(int argc, const char **argv,for (i =0 ; i < active_nr; i++) {const struct cache_entry *ce = active_cache[i]; -if (!match_pathspec (pathspec, ce->name,ce_namelen (ce), -0 , ps_matched,1 ) || - !S_ISGITLINK (ce->ce_mode)) +if (!S_ISGITLINK (ce->ce_mode) || + !match_pathspec (pathspec, ce->name,ce_namelen (ce), +0 , ps_matched,1 ))continue ;ALLOC_GROW (list->entries, list->nr +1 , list->alloc);t/t7400-submodule-basic.sh +14
-2@@ -915,7 +915,20 @@ test_expect_success 'submodule deinit works on repository without submodules' ' >file && git add file && git commit -m "repo should not be empty" && - git submodule deinit . + git submodule deinit + ) +' + +test_expect_success 'submodule deinit refuses to deinit a file' ' + test_when_finished "rm -rf newdirectory" && + mkdir newdirectory && + ( + cd newdirectory && + git init && + >file && + git add file && + git commit -m "repo should not be empty" && + test_must_fail git submodule deinit file ) ' --2.8.0.32.g71f8beb.dirty
Re: [PATCH 10/10] submodule deinit: complain when given a file instead of a submodule
Quoted 7 lines · Per Cederqvist
After this change, what is the simplest way to programmatically deinit any submodule that may exist, without failing if there are none?
"git commit" by default refuses to make an empty commit, but it has the --allow-empty option.
Quoted 6 lines
"git rm -r ." by default fails if there are no files in the repository, but it has the --ignore-unmatch option.
It makes sense that "git submodule deinit ." should fail if there are no submodules, but please add support for --ignore-unmatch at the same time.
Oh right. I'll add the --ignore-unmatch option when rerolling this series.
Thanks,
Stefan
Quoted 75 lines
/ceder
Quoted 70 lines · Stefan Beller
This also improves performance for listing submodules, because
S_ISGITLINKis both faster asmatch_pathspecas well as expected to be true in fewer cases, so putting it first in the condition will speed up the loop to compute all submodules.As this partially reverts
84ba959bbdf0(submodule: fix regression for deinit without submodules, 2016-03-22), this also disallows the use ofgit submodule deinit .to deinit all submodules, when no submodules are present.deinit .continues to work on repositories, which have at least one submodule.CC Per Cederqvist <[email protected]>Signed-off-by Stefan Beller <[email protected]>---
Quoted 3 lines
Patch 10 is a controversial thing I'd assume as it breaks existing users. We should take it for the next major release (i.e. 3.0)
I just want to put it out here now.builtin/submodule--helper.c | 6 +++--- t/t7400-submodule-basic.sh | 15 ++++++++++++++- 2 files changed, 17 insertions(+), 4 deletions(-)builtin/submodule--helper.c +3
-3@@ -242,9 +242,9 @@ static int module_list_compute(int argc, const char **argv,for (i =0 ; i < active_nr; i++) {const struct cache_entry *ce = active_cache[i]; -if (!match_pathspec (pathspec, ce->name,ce_namelen (ce), -0 , ps_matched,1 ) || - !S_ISGITLINK (ce->ce_mode)) +if (!S_ISGITLINK (ce->ce_mode) || + !match_pathspec (pathspec, ce->name,ce_namelen (ce), +0 , ps_matched,1 ))continue ;ALLOC_GROW (list->entries, list->nr +1 , list->alloc);t/t7400-submodule-basic.sh +14
-2@@ -915,7 +915,20 @@ test_expect_success 'submodule deinit works on repository without submodules' ' >file && git add file && git commit -m "repo should not be empty" && - git submodule deinit . + git submodule deinit + ) +' + +test_expect_success 'submodule deinit refuses to deinit a file' ' + test_when_finished "rm -rf newdirectory" && + mkdir newdirectory && + ( + cd newdirectory && + git init && + >file && + git add file && + git commit -m "repo should not be empty" && + test_must_fail git submodule deinit file ) ' --2.8.0.32.g71f8beb.dirty
Re: [PATCH 10/10] submodule deinit: complain when given a file instead of a submodule
Quoted 8 lines · Stefan Beller
Quoted 7 lines · Per Cederqvist
After this change, what is the simplest way to programmatically deinit any submodule that may exist, without failing if there are none?
"git commit" by default refuses to make an empty commit, but it has the --allow-empty option.
Quoted 6 lines
Quoted 6 lines
"git rm -r ." by default fails if there are no files in the repository, but it has the --ignore-unmatch option.
It makes sense that "git submodule deinit ." should fail if there are no submodules, but please add support for --ignore-unmatch at the same time.
With this patch series, you can omit the trailing dot, i.e. "git submodule deinit" works. I just tested that and it works in repositories with no submodules as well as in empty repositories, but I'll add a test for that as well.
Quoted 81 lines
Oh right. I'll add the --ignore-unmatch option when rerolling this series.
Thanks,
StefanQuoted 75 lines
/ceder
Quoted 70 lines · Stefan Beller
This also improves performance for listing submodules, because
S_ISGITLINKis both faster asmatch_pathspecas well as expected to be true in fewer cases, so putting it first in the condition will speed up the loop to compute all submodules.As this partially reverts
84ba959bbdf0(submodule: fix regression for deinit without submodules, 2016-03-22), this also disallows the use ofgit submodule deinit .to deinit all submodules, when no submodules are present.deinit .continues to work on repositories, which have at least one submodule.CC Per Cederqvist <[email protected]>Signed-off-by Stefan Beller <[email protected]>---
Quoted 3 lines
Patch 10 is a controversial thing I'd assume as it breaks existing users. We should take it for the next major release (i.e. 3.0)
I just want to put it out here now.builtin/submodule--helper.c | 6 +++--- t/t7400-submodule-basic.sh | 15 ++++++++++++++- 2 files changed, 17 insertions(+), 4 deletions(-)builtin/submodule--helper.c +3
-3@@ -242,9 +242,9 @@ static int module_list_compute(int argc, const char **argv,for (i =0 ; i < active_nr; i++) {const struct cache_entry *ce = active_cache[i]; -if (!match_pathspec (pathspec, ce->name,ce_namelen (ce), -0 , ps_matched,1 ) || - !S_ISGITLINK (ce->ce_mode)) +if (!S_ISGITLINK (ce->ce_mode) || + !match_pathspec (pathspec, ce->name,ce_namelen (ce), +0 , ps_matched,1 ))continue ;ALLOC_GROW (list->entries, list->nr +1 , list->alloc);t/t7400-submodule-basic.sh +14
-2@@ -915,7 +915,20 @@ test_expect_success 'submodule deinit works on repository without submodules' ' >file && git add file && git commit -m "repo should not be empty" && - git submodule deinit . + git submodule deinit + ) +' + +test_expect_success 'submodule deinit refuses to deinit a file' ' + test_when_finished "rm -rf newdirectory" && + mkdir newdirectory && + ( + cd newdirectory && + git init && + >file && + git add file && + git commit -m "repo should not be empty" && + test_must_fail git submodule deinit file ) ' --2.8.0.32.g71f8beb.dirty