From: Heiko Voigt <hvoigt@hvoigt.net>
To: Junio C Hamano <gitster@pobox.com>
Cc: git@vger.kernel.org, Daniel Milde <daniel@milde.cz>
Subject: [PATCH] Let submodule command exit with error status if path does not exist
Date: Thu, 9 Aug 2012 22:03:04 +0200 [thread overview]
Message-ID: <20120809200302.GA93203@book.hvoigt.net> (raw)
In-Reply-To: <1340872080.2103.92.camel@athena.dnet>
Previously the exit status of git submodule was zero for various
subcommands even though the user specified an unknown path.
The reason behind that was that they all pipe the output of module_list
into the while loop which then does the action on the paths specified by
the commandline. Since piped commands are run in parallel the status
code of module_list was swallowed.
We work around this by introducing a new function module_list_valid
which is used to check the leftover commandline parameters passed to
module_list.
Signed-off-by: Heiko Voigt <hvoigt@hvoigt.net>
---
git-submodule.sh | 19 ++++++++++++++++++-
t/t7400-submodule-basic.sh | 26 ++++++++++++++++++++++----
2 files changed, 40 insertions(+), 5 deletions(-)
diff --git a/git-submodule.sh b/git-submodule.sh
index aac575e..1fd21da 100755
--- a/git-submodule.sh
+++ b/git-submodule.sh
@@ -103,13 +103,21 @@ resolve_relative_url ()
echo "${is_relative:+${up_path}}${remoteurl#./}"
}
+module_list_ls_files() {
+ git ls-files --error-unmatch --stage -- "$@"
+}
+
+module_list_valid() {
+ module_list_ls_files "$@" >/dev/null
+}
+
#
# Get submodule info for registered submodules
# $@ = path to limit submodule list
#
module_list()
{
- git ls-files --error-unmatch --stage -- "$@" |
+ module_list_ls_files "$@" |
perl -e '
my %unmerged = ();
my ($null_sha1) = ("0" x 40);
@@ -434,6 +442,8 @@ cmd_init()
shift
done
+ module_list_valid "$@" || exit 1
+
module_list "$@" |
while read mode sha1 stage sm_path
do
@@ -532,6 +542,8 @@ cmd_update()
cmd_init "--" "$@" || return
fi
+ module_list_valid "$@" || exit 1
+
cloned_modules=
module_list "$@" | {
err=
@@ -929,6 +941,8 @@ cmd_status()
shift
done
+ module_list_valid "$@" || exit 1
+
module_list "$@" |
while read mode sha1 stage sm_path
do
@@ -996,6 +1010,9 @@ cmd_sync()
;;
esac
done
+
+ module_list_valid "$@" || exit 1
+
cd_to_toplevel
module_list "$@" |
while read mode sha1 stage sm_path
diff --git a/t/t7400-submodule-basic.sh b/t/t7400-submodule-basic.sh
index c73bec9..3a40334 100755
--- a/t/t7400-submodule-basic.sh
+++ b/t/t7400-submodule-basic.sh
@@ -258,6 +258,27 @@ test_expect_success 'init should register submodule url in .git/config' '
test_cmp expect url
'
+test_failure_with_unknown_submodule() {
+ test_must_fail git submodule $1 no-such-submodule 2>output.err &&
+ grep "^error: .*no-such-submodule" output.err
+}
+
+test_expect_success 'init should fail with unknown submodule' '
+ test_failure_with_unknown_submodule init
+'
+
+test_expect_success 'update should fail with unknown submodule' '
+ test_failure_with_unknown_submodule update
+'
+
+test_expect_success 'status should fail with unknown submodule' '
+ test_failure_with_unknown_submodule status
+'
+
+test_expect_success 'sync should fail with unknown submodule' '
+ test_failure_with_unknown_submodule sync
+'
+
test_expect_success 'update should fail when path is used by a file' '
echo hello >expect &&
@@ -418,10 +439,7 @@ test_expect_success 'moving to a commit without submodule does not leave empty d
'
test_expect_success 'submodule <invalid-path> warns' '
-
- git submodule no-such-submodule 2> output.err &&
- grep "^error: .*no-such-submodule" output.err
-
+ test_failure_with_unknown_submodule
'
test_expect_success 'add submodules without specifying an explicit path' '
--
1.7.12.rc2.10.g45a4861
next prev parent reply other threads:[~2012-08-09 20:03 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-06-28 8:28 git submodule return status Daniel Milde
2012-08-09 20:03 ` Heiko Voigt [this message]
2012-08-09 20:42 ` [PATCH] Let submodule command exit with error status if path does not exist Junio C Hamano
2012-08-11 6:49 ` [PATCH v2] " Heiko Voigt
2012-08-12 5:43 ` Junio C Hamano
2012-08-13 16:39 ` Heiko Voigt
2012-08-13 17:11 ` Junio C Hamano
2012-08-14 20:35 ` [PATCH v3] " Heiko Voigt
2012-08-14 20:59 ` Junio C Hamano
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20120809200302.GA93203@book.hvoigt.net \
--to=hvoigt@hvoigt.net \
--cc=daniel@milde.cz \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).