summaryrefslogtreecommitdiff
path: root/git-submodule.sh
diff options
context:
space:
mode:
authorKyle Meyer <kyle@kyleam.com>2020-01-08 00:31:21 (GMT)
committerJunio C Hamano <gitster@pobox.com>2020-01-15 18:22:24 (GMT)
commitc81638541cbbf5868e79037ca29b6e37e47461e5 (patch)
tree33c14af5bf2876375fe8590b605415cc855a9357 /git-submodule.sh
parentd0654dc308b0ba76dd8ed7bbb33c8d8f7aacd783 (diff)
downloadgit-c81638541cbbf5868e79037ca29b6e37e47461e5.zip
git-c81638541cbbf5868e79037ca29b6e37e47461e5.tar.gz
git-c81638541cbbf5868e79037ca29b6e37e47461e5.tar.bz2
submodule add: show 'add --dry-run' stderr when aborting
Unless --force is specified, 'submodule add' checks if the destination path is ignored by calling 'git add --dry-run --ignore-missing', and, if that call fails, aborts with a custom "path is ignored" message (a slight variant of what 'git add' shows). Aborting early rather than letting the downstream 'git add' call fail is done so that the command exits before cloning into the destination path. However, in rare cases where the dry-run call fails for a reason other than the path being ignored---for example, due to a preexisting index.lock file---displaying the "ignored path" error message hides the real source of the failure. Instead of displaying the tailored "ignored path" message, let's report the standard error from the dry run to give the caller more accurate information about failures that are not due to an ignored path. For the ignored path case, this leads to the following change in the error message: The following [-path is-]{+paths are+} ignored by one of your .gitignore files: <destination path> Use -f if you really want to add [-it.-]{+them.+} The new phrasing is a bit awkward, because 'submodule add' is only dealing with one destination path. Alternatively, we could continue to use the tailored message when the exit code is 1 (the expected status for a failure due to an ignored path) and relay the standard error for all other non-zero exits. That, however, risks hiding the message of unrelated failures that share an exit code of 1, so it doesn't seem worth doing just to avoid a clunkier, but still clear, error message. Signed-off-by: Kyle Meyer <kyle@kyleam.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'git-submodule.sh')
-rwxr-xr-xgit-submodule.sh14
1 files changed, 8 insertions, 6 deletions
diff --git a/git-submodule.sh b/git-submodule.sh
index aaa1809..afcb4c0 100755
--- a/git-submodule.sh
+++ b/git-submodule.sh
@@ -241,13 +241,15 @@ cmd_add()
die "$(eval_gettext "'\$sm_path' does not have a commit checked out")"
fi
- if test -z "$force" &&
- ! git add --dry-run --ignore-missing --no-warn-embedded-repo "$sm_path" > /dev/null 2>&1
+ if test -z "$force"
then
- eval_gettextln "The following path is ignored by one of your .gitignore files:
-\$sm_path
-Use -f if you really want to add it." >&2
- exit 1
+ dryerr=$(git add --dry-run --ignore-missing --no-warn-embedded-repo "$sm_path" 2>&1 >/dev/null)
+ res=$?
+ if test $res -ne 0
+ then
+ echo >&2 "$dryerr"
+ exit $res
+ fi
fi
if test -n "$custom_name"