зеркало из https://github.com/microsoft/git.git
Merge branch 'hv/submodule-path-unmatch'
* hv/submodule-path-unmatch: Let submodule command exit with error status if path does not exist
This commit is contained in:
Коммит
1c0fa76be7
|
@ -109,26 +109,48 @@ resolve_relative_url ()
|
||||||
#
|
#
|
||||||
module_list()
|
module_list()
|
||||||
{
|
{
|
||||||
git ls-files --error-unmatch --stage -- "$@" |
|
(
|
||||||
|
git ls-files --error-unmatch --stage -- "$@" ||
|
||||||
|
echo "unmatched pathspec exists"
|
||||||
|
) |
|
||||||
perl -e '
|
perl -e '
|
||||||
my %unmerged = ();
|
my %unmerged = ();
|
||||||
my ($null_sha1) = ("0" x 40);
|
my ($null_sha1) = ("0" x 40);
|
||||||
|
my @out = ();
|
||||||
|
my $unmatched = 0;
|
||||||
while (<STDIN>) {
|
while (<STDIN>) {
|
||||||
|
if (/^unmatched pathspec/) {
|
||||||
|
$unmatched = 1;
|
||||||
|
next;
|
||||||
|
}
|
||||||
chomp;
|
chomp;
|
||||||
my ($mode, $sha1, $stage, $path) =
|
my ($mode, $sha1, $stage, $path) =
|
||||||
/^([0-7]+) ([0-9a-f]{40}) ([0-3])\t(.*)$/;
|
/^([0-7]+) ([0-9a-f]{40}) ([0-3])\t(.*)$/;
|
||||||
next unless $mode eq "160000";
|
next unless $mode eq "160000";
|
||||||
if ($stage ne "0") {
|
if ($stage ne "0") {
|
||||||
if (!$unmerged{$path}++) {
|
if (!$unmerged{$path}++) {
|
||||||
print "$mode $null_sha1 U\t$path\n";
|
push @out, "$mode $null_sha1 U\t$path\n";
|
||||||
}
|
}
|
||||||
next;
|
next;
|
||||||
}
|
}
|
||||||
print "$_\n";
|
push @out, "$_\n";
|
||||||
|
}
|
||||||
|
if ($unmatched) {
|
||||||
|
print "#unmatched\n";
|
||||||
|
} else {
|
||||||
|
print for (@out);
|
||||||
}
|
}
|
||||||
'
|
'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
die_if_unmatched ()
|
||||||
|
{
|
||||||
|
if test "$1" = "#unmatched"
|
||||||
|
then
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
#
|
#
|
||||||
# Map submodule path to submodule name
|
# Map submodule path to submodule name
|
||||||
#
|
#
|
||||||
|
@ -385,6 +407,7 @@ cmd_foreach()
|
||||||
module_list |
|
module_list |
|
||||||
while read mode sha1 stage sm_path
|
while read mode sha1 stage sm_path
|
||||||
do
|
do
|
||||||
|
die_if_unmatched "$mode"
|
||||||
if test -e "$sm_path"/.git
|
if test -e "$sm_path"/.git
|
||||||
then
|
then
|
||||||
say "$(eval_gettext "Entering '\$prefix\$sm_path'")"
|
say "$(eval_gettext "Entering '\$prefix\$sm_path'")"
|
||||||
|
@ -437,6 +460,7 @@ cmd_init()
|
||||||
module_list "$@" |
|
module_list "$@" |
|
||||||
while read mode sha1 stage sm_path
|
while read mode sha1 stage sm_path
|
||||||
do
|
do
|
||||||
|
die_if_unmatched "$mode"
|
||||||
name=$(module_name "$sm_path") || exit
|
name=$(module_name "$sm_path") || exit
|
||||||
|
|
||||||
# Copy url setting when it is not set yet
|
# Copy url setting when it is not set yet
|
||||||
|
@ -537,6 +561,7 @@ cmd_update()
|
||||||
err=
|
err=
|
||||||
while read mode sha1 stage sm_path
|
while read mode sha1 stage sm_path
|
||||||
do
|
do
|
||||||
|
die_if_unmatched "$mode"
|
||||||
if test "$stage" = U
|
if test "$stage" = U
|
||||||
then
|
then
|
||||||
echo >&2 "Skipping unmerged submodule $sm_path"
|
echo >&2 "Skipping unmerged submodule $sm_path"
|
||||||
|
@ -932,6 +957,7 @@ cmd_status()
|
||||||
module_list "$@" |
|
module_list "$@" |
|
||||||
while read mode sha1 stage sm_path
|
while read mode sha1 stage sm_path
|
||||||
do
|
do
|
||||||
|
die_if_unmatched "$mode"
|
||||||
name=$(module_name "$sm_path") || exit
|
name=$(module_name "$sm_path") || exit
|
||||||
url=$(git config submodule."$name".url)
|
url=$(git config submodule."$name".url)
|
||||||
displaypath="$prefix$sm_path"
|
displaypath="$prefix$sm_path"
|
||||||
|
@ -1000,6 +1026,7 @@ cmd_sync()
|
||||||
module_list "$@" |
|
module_list "$@" |
|
||||||
while read mode sha1 stage sm_path
|
while read mode sha1 stage sm_path
|
||||||
do
|
do
|
||||||
|
die_if_unmatched "$mode"
|
||||||
name=$(module_name "$sm_path")
|
name=$(module_name "$sm_path")
|
||||||
url=$(git config -f .gitmodules --get submodule."$name".url)
|
url=$(git config -f .gitmodules --get submodule."$name".url)
|
||||||
|
|
||||||
|
|
|
@ -258,6 +258,27 @@ test_expect_success 'init should register submodule url in .git/config' '
|
||||||
test_cmp expect url
|
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' '
|
test_expect_success 'update should fail when path is used by a file' '
|
||||||
echo hello >expect &&
|
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' '
|
test_expect_success 'submodule <invalid-path> warns' '
|
||||||
|
test_failure_with_unknown_submodule
|
||||||
git submodule no-such-submodule 2> output.err &&
|
|
||||||
grep "^error: .*no-such-submodule" output.err
|
|
||||||
|
|
||||||
'
|
'
|
||||||
|
|
||||||
test_expect_success 'add submodules without specifying an explicit path' '
|
test_expect_success 'add submodules without specifying an explicit path' '
|
||||||
|
|
Загрузка…
Ссылка в новой задаче