diff options
author | Junio C Hamano <gitster@pobox.com> | 2020-02-06 01:34:58 +0300 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2020-02-06 01:34:59 +0300 |
commit | 25794d6ce9f34ed5dedc569c5050afdb04518744 (patch) | |
tree | 4e6ae4f1481255ae051b85489ca39f20b7380dff | |
parent | d0e70cd32e95df3be2250536f9089c858a298874 (diff) | |
parent | c81638541cbbf5868e79037ca29b6e37e47461e5 (diff) |
Merge branch 'km/submodule-add-errmsg'
Improve error message generation for "git submodule add".
* km/submodule-add-errmsg:
submodule add: show 'add --dry-run' stderr when aborting
-rwxr-xr-x | git-submodule.sh | 14 | ||||
-rwxr-xr-x | t/t7400-submodule-basic.sh | 15 |
2 files changed, 21 insertions, 8 deletions
diff --git a/git-submodule.sh b/git-submodule.sh index aaa1809d24..afcb4c0948 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" diff --git a/t/t7400-submodule-basic.sh b/t/t7400-submodule-basic.sh index 7f75bb1be6..42a00f95b9 100755 --- a/t/t7400-submodule-basic.sh +++ b/t/t7400-submodule-basic.sh @@ -156,9 +156,9 @@ test_expect_success 'submodule add to .gitignored path fails' ' ( cd addtest-ignore && cat <<-\EOF >expect && - The following path is ignored by one of your .gitignore files: + The following paths are ignored by one of your .gitignore files: submod - Use -f if you really want to add it. + Use -f if you really want to add them. EOF # Does not use test_commit due to the ignore echo "*" > .gitignore && @@ -191,6 +191,17 @@ test_expect_success 'submodule add to reconfigure existing submodule with --forc ) ' +test_expect_success 'submodule add relays add --dry-run stderr' ' + test_when_finished "rm -rf addtest/.git/index.lock" && + ( + cd addtest && + : >.git/index.lock && + ! git submodule add "$submodurl" sub-while-locked 2>output.err && + test_i18ngrep "^fatal: .*index\.lock" output.err && + test_path_is_missing sub-while-locked + ) +' + test_expect_success 'submodule add --branch' ' echo "refs/heads/initial" >expect-head && cat <<-\EOF >expect-heads && |