Merge branch 'jk/submodule-subdirectory-ok'

Allow various subcommands of "git submodule" to be run not from the
top of the working tree of the superproject.

* jk/submodule-subdirectory-ok:
  submodule: drop the top-level requirement
  rev-parse: add --prefix option
  submodule: show full path in error message
  t7403: add missing && chaining
  t7403: modernize style
  t7401: make indentation consistent
This commit is contained in:
Junio C Hamano 2013-06-30 15:39:35 -07:00
Родитель 3c36e8a40d 091a6eb0fe
Коммит d9857bfd4d
9 изменённых файлов: 676 добавлений и 216 удалений

Просмотреть файл

@ -59,6 +59,22 @@ OPTIONS
If there is no parameter given by the user, use `<arg>`
instead.
--prefix <arg>::
Behave as if 'git rev-parse' was invoked from the `<arg>`
subdirectory of the working tree. Any relative filenames are
resolved as if they are prefixed by `<arg>` and will be printed
in that form.
+
This can be used to convert arguments to a command run in a subdirectory
so that they can still be used after moving to the top-level of the
repository. For example:
+
----
prefix=$(git rev-parse --show-prefix)
cd "$(git rev-parse --show-toplevel)"
eval "set -- $(git rev-parse --sq --prefix "$prefix" "$@")"
----
--verify::
Verify that exactly one parameter is provided, and that it
can be turned into a raw 20-byte SHA-1 that can be used to

Просмотреть файл

@ -212,11 +212,17 @@ static void show_datestring(const char *flag, const char *datestr)
show(buffer);
}
static int show_file(const char *arg)
static int show_file(const char *arg, int output_prefix)
{
show_default();
if ((filter & (DO_NONFLAGS|DO_NOREV)) == (DO_NONFLAGS|DO_NOREV)) {
show(arg);
if (output_prefix) {
const char *prefix = startup_info->prefix;
show(prefix_filename(prefix,
prefix ? strlen(prefix) : 0,
arg));
} else
show(arg);
return 1;
}
return 0;
@ -470,6 +476,7 @@ N_("git rev-parse --parseopt [options] -- [<args>...]\n"
int cmd_rev_parse(int argc, const char **argv, const char *prefix)
{
int i, as_is = 0, verify = 0, quiet = 0, revs_count = 0, type = 0;
int output_prefix = 0;
unsigned char sha1[20];
const char *name = NULL;
@ -503,7 +510,7 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix)
const char *arg = argv[i];
if (as_is) {
if (show_file(arg) && as_is < 2)
if (show_file(arg, output_prefix) && as_is < 2)
verify_filename(prefix, arg, 0);
continue;
}
@ -527,7 +534,7 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix)
as_is = 2;
/* Pass on the "--" if we show anything but files.. */
if (filter & (DO_FLAGS | DO_REVS))
show_file(arg);
show_file(arg, 0);
continue;
}
if (!strcmp(arg, "--default")) {
@ -535,6 +542,13 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix)
i++;
continue;
}
if (!strcmp(arg, "--prefix")) {
prefix = argv[i+1];
startup_info->prefix = prefix;
output_prefix = 1;
i++;
continue;
}
if (!strcmp(arg, "--revs-only")) {
filter &= ~DO_NOREV;
continue;
@ -754,7 +768,7 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix)
if (verify)
die_no_single_rev(quiet);
as_is = 1;
if (!show_file(arg))
if (!show_file(arg, output_prefix))
continue;
verify_filename(prefix, arg, 1);
}

Просмотреть файл

@ -14,10 +14,13 @@ USAGE="[--quiet] add [-b <branch>] [-f|--force] [--name <name>] [--reference <re
or: $dashless [--quiet] foreach [--recursive] <command>
or: $dashless [--quiet] sync [--recursive] [--] [<path>...]"
OPTIONS_SPEC=
SUBDIRECTORY_OK=Yes
. git-sh-setup
. git-sh-i18n
. git-parse-remote
require_work_tree
wt_prefix=$(git rev-parse --show-prefix)
cd_to_toplevel
command=
branch=
@ -106,12 +109,48 @@ resolve_relative_url ()
echo "${is_relative:+${up_path}}${remoteurl#./}"
}
# Resolve a path to be relative to another path. This is intended for
# converting submodule paths when git-submodule is run in a subdirectory
# and only handles paths where the directory separator is '/'.
#
# The output is the first argument as a path relative to the second argument,
# which defaults to $wt_prefix if it is omitted.
relative_path ()
{
local target curdir result
target=$1
curdir=${2-$wt_prefix}
curdir=${curdir%/}
result=
while test -n "$curdir"
do
case "$target" in
"$curdir/"*)
target=${target#"$curdir"/}
break
;;
esac
result="${result}../"
if test "$curdir" = "${curdir%/*}"
then
curdir=
else
curdir="${curdir%/*}"
fi
done
echo "$result$target"
}
#
# Get submodule info for registered submodules
# $@ = path to limit submodule list
#
module_list()
{
eval "set $(git rev-parse --sq --prefix "$wt_prefix" -- "$@")"
(
git ls-files -z --error-unmatch --stage -- "$@" ||
echo "unmatched pathspec exists"
@ -283,6 +322,7 @@ isnumber()
cmd_add()
{
# parse $args after "submodule ... add".
reference_path=
while test $# -ne 0
do
case "$1" in
@ -299,11 +339,11 @@ cmd_add()
;;
--reference)
case "$2" in '') usage ;; esac
reference="--reference=$2"
reference_path=$2
shift
;;
--reference=*)
reference="$1"
reference_path="${1#--reference=}"
;;
--name)
case "$2" in '') usage ;; esac
@ -324,6 +364,14 @@ cmd_add()
shift
done
if test -n "$reference_path"
then
is_absolute_path "$reference_path" ||
reference_path="$wt_prefix$reference_path"
reference="--reference=$reference_path"
fi
repo=$1
sm_path=$2
@ -336,9 +384,14 @@ cmd_add()
usage
fi
is_absolute_path "$sm_path" || sm_path="$wt_prefix$sm_path"
# assure repo is absolute or relative to parent
case "$repo" in
./*|../*)
test -z "$wt_prefix" ||
die "$(gettext "Relative path can only be used from the toplevel of the working tree")"
# dereference source url relative to parent's url
realrepo=$(resolve_relative_url "$repo") || exit
;;
@ -472,21 +525,23 @@ cmd_foreach()
die_if_unmatched "$mode"
if test -e "$sm_path"/.git
then
say "$(eval_gettext "Entering '\$prefix\$sm_path'")"
displaypath=$(relative_path "$sm_path")
say "$(eval_gettext "Entering '\$prefix\$displaypath'")"
name=$(module_name "$sm_path")
(
prefix="$prefix$sm_path/"
clear_local_git_env
# we make $path available to scripts ...
path=$sm_path
cd "$sm_path" &&
sm_path=$(relative_path "$sm_path") &&
# we make $path available to scripts ...
path=$sm_path &&
eval "$@" &&
if test -n "$recursive"
then
cmd_foreach "--recursive" "$@"
fi
) <&3 3<&- ||
die "$(eval_gettext "Stopping at '\$sm_path'; script returned non-zero status.")"
die "$(eval_gettext "Stopping at '\$prefix\$displaypath'; script returned non-zero status.")"
fi
done
}
@ -525,12 +580,14 @@ cmd_init()
die_if_unmatched "$mode"
name=$(module_name "$sm_path") || exit
displaypath=$(relative_path "$sm_path")
# Copy url setting when it is not set yet
if test -z "$(git config "submodule.$name.url")"
then
url=$(git config -f .gitmodules submodule."$name".url)
test -z "$url" &&
die "$(eval_gettext "No url found for submodule path '\$sm_path' in .gitmodules")"
die "$(eval_gettext "No url found for submodule path '\$displaypath' in .gitmodules")"
# Possibly a url relative to parent
case "$url" in
@ -539,9 +596,9 @@ cmd_init()
;;
esac
git config submodule."$name".url "$url" ||
die "$(eval_gettext "Failed to register url for submodule path '\$sm_path'")"
die "$(eval_gettext "Failed to register url for submodule path '\$displaypath'")"
say "$(eval_gettext "Submodule '\$name' (\$url) registered for path '\$sm_path'")"
say "$(eval_gettext "Submodule '\$name' (\$url) registered for path '\$displaypath'")"
fi
# Copy "update" setting when it is not set yet
@ -549,7 +606,7 @@ cmd_init()
test -z "$upd" ||
test -n "$(git config submodule."$name".update)" ||
git config submodule."$name".update "$upd" ||
die "$(eval_gettext "Failed to register update mode for submodule path '\$sm_path'")"
die "$(eval_gettext "Failed to register update mode for submodule path '\$displaypath'")"
done
}
@ -595,27 +652,29 @@ cmd_deinit()
die_if_unmatched "$mode"
name=$(module_name "$sm_path") || exit
displaypath=$(relative_path "$sm_path")
# Remove the submodule work tree (unless the user already did it)
if test -d "$sm_path"
then
# Protect submodules containing a .git directory
if test -d "$sm_path/.git"
then
echo >&2 "$(eval_gettext "Submodule work tree '\$sm_path' contains a .git directory")"
echo >&2 "$(eval_gettext "Submodule work tree '\$displaypath' contains a .git directory")"
die "$(eval_gettext "(use 'rm -rf' if you really want to remove it including all of its history)")"
fi
if test -z "$force"
then
git rm -qn "$sm_path" ||
die "$(eval_gettext "Submodule work tree '\$sm_path' contains local modifications; use '-f' to discard them")"
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 '\$sm_path'")" ||
say "$(eval_gettext "Could not remove submodule work tree '\$sm_path'")"
say "$(eval_gettext "Cleared directory '\$displaypath'")" ||
say "$(eval_gettext "Could not remove submodule work tree '\$displaypath'")"
fi
mkdir "$sm_path" || say "$(eval_gettext "Could not create empty submodule directory '\$sm_path'")"
mkdir "$sm_path" || say "$(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\.")"
@ -624,7 +683,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 '\$sm_path'")"
say "$(eval_gettext "Submodule '\$name' (\$url) unregistered for path '\$displaypath'")"
fi
done
}
@ -718,9 +777,11 @@ cmd_update()
update_module=$(git config submodule."$name".update)
fi
displaypath=$(relative_path "$prefix$sm_path")
if test "$update_module" = "none"
then
echo "Skipping submodule '$prefix$sm_path'"
echo "Skipping submodule '$displaypath'"
continue
fi
@ -729,7 +790,7 @@ cmd_update()
# Only mention uninitialized submodules when its
# path have been specified
test "$#" != "0" &&
say "$(eval_gettext "Submodule path '\$prefix\$sm_path' not initialized
say "$(eval_gettext "Submodule path '\$displaypath' not initialized
Maybe you want to use 'update --init'?")"
continue
fi
@ -742,7 +803,7 @@ Maybe you want to use 'update --init'?")"
else
subsha1=$(clear_local_git_env; cd "$sm_path" &&
git rev-parse --verify HEAD) ||
die "$(eval_gettext "Unable to find current revision in submodule path '\$prefix\$sm_path'")"
die "$(eval_gettext "Unable to find current revision in submodule path '\$displaypath'")"
fi
if test -n "$remote"
@ -775,7 +836,7 @@ Maybe you want to use 'update --init'?")"
(clear_local_git_env; cd "$sm_path" &&
( (rev=$(git rev-list -n 1 $sha1 --not --all 2>/dev/null) &&
test -z "$rev") || git-fetch)) ||
die "$(eval_gettext "Unable to fetch in submodule path '\$prefix\$sm_path'")"
die "$(eval_gettext "Unable to fetch in submodule path '\$displaypath'")"
fi
# Is this something we just cloned?
@ -789,20 +850,20 @@ Maybe you want to use 'update --init'?")"
case "$update_module" in
rebase)
command="git rebase"
die_msg="$(eval_gettext "Unable to rebase '\$sha1' in submodule path '\$prefix\$sm_path'")"
say_msg="$(eval_gettext "Submodule path '\$prefix\$sm_path': rebased into '\$sha1'")"
die_msg="$(eval_gettext "Unable to rebase '\$sha1' in submodule path '\$displaypath'")"
say_msg="$(eval_gettext "Submodule path '\$displaypath': rebased into '\$sha1'")"
must_die_on_failure=yes
;;
merge)
command="git merge"
die_msg="$(eval_gettext "Unable to merge '\$sha1' in submodule path '\$prefix\$sm_path'")"
say_msg="$(eval_gettext "Submodule path '\$prefix\$sm_path': merged in '\$sha1'")"
die_msg="$(eval_gettext "Unable to merge '\$sha1' in submodule path '\$displaypath'")"
say_msg="$(eval_gettext "Submodule path '\$displaypath': merged in '\$sha1'")"
must_die_on_failure=yes
;;
*)
command="git checkout $subforce -q"
die_msg="$(eval_gettext "Unable to checkout '\$sha1' in submodule path '\$prefix\$sm_path'")"
say_msg="$(eval_gettext "Submodule path '\$prefix\$sm_path': checked out '\$sha1'")"
die_msg="$(eval_gettext "Unable to checkout '\$sha1' in submodule path '\$displaypath'")"
say_msg="$(eval_gettext "Submodule path '\$displaypath': checked out '\$sha1'")"
;;
esac
@ -829,7 +890,7 @@ Maybe you want to use 'update --init'?")"
res=$?
if test $res -gt 0
then
die_msg="$(eval_gettext "Failed to recurse into submodule path '\$prefix\$sm_path'")"
die_msg="$(eval_gettext "Failed to recurse into submodule path '\$displaypath'")"
if test $res -eq 1
then
err="${err};$die_msg"
@ -943,6 +1004,7 @@ cmd_summary() {
fi
cd_to_toplevel
eval "set $(git rev-parse --sq --prefix "$wt_prefix" -- "$@")"
# Get modified modules cared by user
modules=$(git $diff_cmd $cached --ignore-submodules=dirty --raw $head -- "$@" |
sane_egrep '^:([0-7]* )?160000' |
@ -992,16 +1054,18 @@ cmd_summary() {
! GIT_DIR="$name/.git" git-rev-parse -q --verify $sha1_dst^0 >/dev/null &&
missing_dst=t
display_name=$(relative_path "$name")
total_commits=
case "$missing_src,$missing_dst" in
t,)
errmsg="$(eval_gettext " Warn: \$name doesn't contain commit \$sha1_src")"
errmsg="$(eval_gettext " Warn: \$display_name doesn't contain commit \$sha1_src")"
;;
,t)
errmsg="$(eval_gettext " Warn: \$name doesn't contain commit \$sha1_dst")"
errmsg="$(eval_gettext " Warn: \$display_name doesn't contain commit \$sha1_dst")"
;;
t,t)
errmsg="$(eval_gettext " Warn: \$name doesn't contain commits \$sha1_src and \$sha1_dst")"
errmsg="$(eval_gettext " Warn: \$display_name doesn't contain commits \$sha1_src and \$sha1_dst")"
;;
*)
errmsg=
@ -1030,12 +1094,12 @@ cmd_summary() {
submodule="$(gettext "submodule")"
if test $mod_dst = 160000
then
echo "* $name $sha1_abbr_src($blob)->$sha1_abbr_dst($submodule)$total_commits:"
echo "* $display_name $sha1_abbr_src($blob)->$sha1_abbr_dst($submodule)$total_commits:"
else
echo "* $name $sha1_abbr_src($submodule)->$sha1_abbr_dst($blob)$total_commits:"
echo "* $display_name $sha1_abbr_src($submodule)->$sha1_abbr_dst($blob)$total_commits:"
fi
else
echo "* $name $sha1_abbr_src...$sha1_abbr_dst$total_commits:"
echo "* $display_name $sha1_abbr_src...$sha1_abbr_dst$total_commits:"
fi
if test -n "$errmsg"
then
@ -1119,7 +1183,7 @@ cmd_status()
die_if_unmatched "$mode"
name=$(module_name "$sm_path") || exit
url=$(git config submodule."$name".url)
displaypath="$prefix$sm_path"
displaypath=$(relative_path "$prefix$sm_path")
if test "$stage" = U
then
say "U$sha1 $displaypath"
@ -1214,7 +1278,8 @@ cmd_sync()
if git config "submodule.$name.url" >/dev/null 2>/dev/null
then
say "$(eval_gettext "Synchronizing submodule url for '\$prefix\$sm_path'")"
displaypath=$(relative_path "$prefix$sm_path")
say "$(eval_gettext "Synchronizing submodule url for '\$displaypath'")"
git config submodule."$name".url "$super_config_url"
if test -e "$sm_path"/.git

96
t/t1513-rev-parse-prefix.sh Executable file
Просмотреть файл

@ -0,0 +1,96 @@
#!/bin/sh
test_description='Tests for rev-parse --prefix'
. ./test-lib.sh
test_expect_success 'setup' '
mkdir -p sub1/sub2 &&
echo top >top &&
echo file1 >sub1/file1 &&
echo file2 >sub1/sub2/file2 &&
git add top sub1/file1 sub1/sub2/file2 &&
git commit -m commit
'
test_expect_success 'empty prefix -- file' '
git rev-parse --prefix "" -- top sub1/file1 >actual &&
cat <<-\EOF >expected &&
--
top
sub1/file1
EOF
test_cmp expected actual
'
test_expect_success 'valid prefix -- file' '
git rev-parse --prefix sub1/ -- file1 sub2/file2 >actual &&
cat <<-\EOF >expected &&
--
sub1/file1
sub1/sub2/file2
EOF
test_cmp expected actual
'
test_expect_success 'valid prefix -- ../file' '
git rev-parse --prefix sub1/ -- ../top sub2/file2 >actual &&
cat <<-\EOF >expected &&
--
sub1/../top
sub1/sub2/file2
EOF
test_cmp expected actual
'
test_expect_success 'empty prefix HEAD:./path' '
git rev-parse --prefix "" HEAD:./top >actual &&
git rev-parse HEAD:top >expected &&
test_cmp expected actual
'
test_expect_success 'valid prefix HEAD:./path' '
git rev-parse --prefix sub1/ HEAD:./file1 >actual &&
git rev-parse HEAD:sub1/file1 >expected &&
test_cmp expected actual
'
test_expect_success 'valid prefix HEAD:../path' '
git rev-parse --prefix sub1/ HEAD:../top >actual &&
git rev-parse HEAD:top >expected &&
test_cmp expected actual
'
test_expect_success 'prefix ignored with HEAD:top' '
git rev-parse --prefix sub1/ HEAD:top >actual &&
git rev-parse HEAD:top >expected &&
test_cmp expected actual
'
test_expect_success 'disambiguate path with valid prefix' '
git rev-parse --prefix sub1/ file1 >actual &&
cat <<-\EOF >expected &&
sub1/file1
EOF
test_cmp expected actual
'
test_expect_success 'file and refs with prefix' '
git rev-parse --prefix sub1/ master file1 >actual &&
cat <<-EOF >expected &&
$(git rev-parse master)
sub1/file1
EOF
test_cmp expected actual
'
test_expect_success 'two-levels deep' '
git rev-parse --prefix sub1/sub2/ -- file2 >actual &&
cat <<-\EOF >expected &&
--
sub1/sub2/file2
EOF
test_cmp expected actual
'
test_done

Просмотреть файл

@ -212,6 +212,32 @@ test_expect_success 'submodule add with ./, /.. and // in path' '
test_cmp empty untracked
'
test_expect_success 'submodule add in subdirectory' '
echo "refs/heads/master" >expect &&
>empty &&
mkdir addtest/sub &&
(
cd addtest/sub &&
git submodule add "$submodurl" ../realsubmod3 &&
git submodule init
) &&
rm -f heads head untracked &&
inspect addtest/realsubmod3 ../.. &&
test_cmp expect heads &&
test_cmp expect head &&
test_cmp empty untracked
'
test_expect_success 'submodule add in subdirectory with relative path should fail' '
(
cd addtest/sub &&
test_must_fail git submodule add ../../ submod3 2>../../output.err
) &&
test_i18ngrep toplevel output.err
'
test_expect_success 'setup - add an example entry to .gitmodules' '
GIT_CONFIG=.gitmodules \
git config submodule.example.url git://example.com/init.git
@ -319,6 +345,26 @@ test_expect_success 'status should be "up-to-date" after update' '
grep "^ $rev1" list
'
test_expect_success 'status "up-to-date" from subdirectory' '
mkdir -p sub &&
(
cd sub &&
git submodule status >../list
) &&
grep "^ $rev1" list &&
grep "\\.\\./init" list
'
test_expect_success 'status "up-to-date" from subdirectory with path' '
mkdir -p sub &&
(
cd sub &&
git submodule status ../init >../list
) &&
grep "^ $rev1" list &&
grep "\\.\\./init" list
'
test_expect_success 'status should be "modified" after submodule commit' '
(
cd init &&
@ -399,6 +445,25 @@ test_expect_success 'update --init' '
git rev-parse --resolve-git-dir init/.git
'
test_expect_success 'update --init from subdirectory' '
mv init init2 &&
git config -f .gitmodules submodule.example.url "$(pwd)/init2" &&
git config --remove-section submodule.example &&
test_must_fail git config submodule.example.url &&
mkdir -p sub &&
(
cd sub &&
git submodule update ../init >update.out &&
cat update.out &&
test_i18ngrep "not initialized" update.out &&
test_must_fail git rev-parse --resolve-git-dir ../init/.git &&
git submodule update --init ../init
) &&
git rev-parse --resolve-git-dir init/.git
'
test_expect_success 'do not add files from a submodule' '
git reset --hard &&
@ -772,6 +837,21 @@ test_expect_success 'submodule deinit should remove the whole submodule section
rmdir init
'
test_expect_success 'submodule deinit from subdirectory' '
git submodule update --init &&
git config submodule.example.foo bar &&
mkdir -p sub &&
(
cd sub &&
git submodule deinit ../init >../output
) &&
grep "\\.\\./init" output &&
test -z "$(git config --get-regexp "submodule\.example\.")" &&
test -n "$(git config --get-regexp "submodule\.example2\.")" &&
test -f example2/.git &&
rmdir init
'
test_expect_success 'submodule deinit . deinits all initialized submodules' '
git submodule update --init &&
git config submodule.example.foo bar &&

Просмотреть файл

@ -45,6 +45,42 @@ EOF
test_cmp expected actual
"
test_expect_success 'added submodule (subdirectory)' "
mkdir sub &&
(
cd sub &&
git submodule summary >../actual
) &&
cat >expected <<-EOF &&
* ../sm1 0000000...$head1 (2):
> Add foo2
EOF
test_cmp expected actual
"
test_expect_success 'added submodule (subdirectory only)' "
(
cd sub &&
git submodule summary . >../actual
) &&
>expected &&
test_cmp expected actual
"
test_expect_success 'added submodule (subdirectory with explicit path)' "
(
cd sub &&
git submodule summary ../sm1 >../actual
) &&
cat >expected <<-EOF &&
* ../sm1 0000000...$head1 (2):
> Add foo2
EOF
test_cmp expected actual
"
commit_file sm1 &&
head2=$(add_file sm1 foo3)
@ -76,8 +112,8 @@ head3=$(
)
test_expect_success 'modified submodule(backward)' "
git submodule summary >actual &&
cat >expected <<-EOF &&
git submodule summary >actual &&
cat >expected <<-EOF &&
* sm1 $head2...$head3 (2):
< Add foo3
< Add foo2
@ -89,8 +125,8 @@ EOF
head4=$(add_file sm1 foo4 foo5) &&
head4_full=$(GIT_DIR=sm1/.git git rev-parse --verify HEAD)
test_expect_success 'modified submodule(backward and forward)' "
git submodule summary >actual &&
cat >expected <<-EOF &&
git submodule summary >actual &&
cat >expected <<-EOF &&
* sm1 $head2...$head4 (4):
> Add foo5
> Add foo4
@ -102,15 +138,15 @@ EOF
"
test_expect_success '--summary-limit' "
git submodule summary -n 3 >actual &&
cat >expected <<-EOF &&
git submodule summary -n 3 >actual &&
cat >expected <<-EOF &&
* sm1 $head2...$head4 (4):
> Add foo5
> Add foo4
< Add foo3
EOF
test_cmp expected actual
test_cmp expected actual
"
commit_file sm1 &&
@ -122,8 +158,8 @@ rm -f sm1 &&
mv sm1-bak sm1
test_expect_success 'typechanged submodule(submodule->blob), --cached' "
git submodule summary --cached >actual &&
cat >expected <<-EOF &&
git submodule summary --cached >actual &&
cat >expected <<-EOF &&
* sm1 $head4(submodule)->$head5(blob) (3):
< Add foo5
@ -132,59 +168,59 @@ EOF
"
test_expect_success 'typechanged submodule(submodule->blob), --files' "
git submodule summary --files >actual &&
cat >expected <<-EOF &&
git submodule summary --files >actual &&
cat >expected <<-EOF &&
* sm1 $head5(blob)->$head4(submodule) (3):
> Add foo5
EOF
test_i18ncmp actual expected
test_i18ncmp actual expected
"
rm -rf sm1 &&
git checkout-index sm1
test_expect_success 'typechanged submodule(submodule->blob)' "
git submodule summary >actual &&
cat >expected <<-EOF &&
git submodule summary >actual &&
cat >expected <<-EOF &&
* sm1 $head4(submodule)->$head5(blob):
EOF
test_i18ncmp actual expected
test_i18ncmp actual expected
"
rm -f sm1 &&
test_create_repo sm1 &&
head6=$(add_file sm1 foo6 foo7)
test_expect_success 'nonexistent commit' "
git submodule summary >actual &&
cat >expected <<-EOF &&
git submodule summary >actual &&
cat >expected <<-EOF &&
* sm1 $head4...$head6:
Warn: sm1 doesn't contain commit $head4_full
EOF
test_i18ncmp actual expected
test_i18ncmp actual expected
"
commit_file
test_expect_success 'typechanged submodule(blob->submodule)' "
git submodule summary >actual &&
cat >expected <<-EOF &&
git submodule summary >actual &&
cat >expected <<-EOF &&
* sm1 $head5(blob)->$head6(submodule) (2):
> Add foo7
EOF
test_i18ncmp expected actual
test_i18ncmp expected actual
"
commit_file sm1 &&
rm -rf sm1
test_expect_success 'deleted submodule' "
git submodule summary >actual &&
cat >expected <<-EOF &&
git submodule summary >actual &&
cat >expected <<-EOF &&
* sm1 $head6...0000000:
EOF
test_cmp expected actual
test_cmp expected actual
"
test_create_repo sm2 &&
@ -192,43 +228,43 @@ head7=$(add_file sm2 foo8 foo9) &&
git add sm2
test_expect_success 'multiple submodules' "
git submodule summary >actual &&
cat >expected <<-EOF &&
git submodule summary >actual &&
cat >expected <<-EOF &&
* sm1 $head6...0000000:
* sm2 0000000...$head7 (2):
> Add foo9
EOF
test_cmp expected actual
test_cmp expected actual
"
test_expect_success 'path filter' "
git submodule summary sm2 >actual &&
cat >expected <<-EOF &&
git submodule summary sm2 >actual &&
cat >expected <<-EOF &&
* sm2 0000000...$head7 (2):
> Add foo9
EOF
test_cmp expected actual
test_cmp expected actual
"
commit_file sm2
test_expect_success 'given commit' "
git submodule summary HEAD^ >actual &&
cat >expected <<-EOF &&
git submodule summary HEAD^ >actual &&
cat >expected <<-EOF &&
* sm1 $head6...0000000:
* sm2 0000000...$head7 (2):
> Add foo9
EOF
test_cmp expected actual
test_cmp expected actual
"
test_expect_success '--for-status' "
git submodule summary --for-status HEAD^ >actual &&
test_i18ncmp actual - <<EOF
git submodule summary --for-status HEAD^ >actual &&
test_i18ncmp actual - <<EOF
# Submodule changes to be committed:
#
# * sm1 $head6...0000000:
@ -240,14 +276,14 @@ EOF
"
test_expect_success 'fail when using --files together with --cached' "
test_must_fail git submodule summary --files --cached
test_must_fail git submodule summary --files --cached
"
test_expect_success 'should not fail in an empty repo' "
git init xyzzy &&
cd xyzzy &&
git submodule summary >output 2>&1 &&
test_cmp output /dev/null
git init xyzzy &&
cd xyzzy &&
git submodule summary >output 2>&1 &&
test_cmp output /dev/null
"
test_done

Просмотреть файл

@ -11,216 +11,338 @@ These tests exercise the "git submodule sync" subcommand.
. ./test-lib.sh
test_expect_success setup '
echo file > file &&
echo file >file &&
git add file &&
test_tick &&
git commit -m upstream &&
git clone . super &&
git clone super submodule &&
(cd submodule &&
git submodule add ../submodule sub-submodule &&
test_tick &&
git commit -m "sub-submodule"
(
cd submodule &&
git submodule add ../submodule sub-submodule &&
test_tick &&
git commit -m "sub-submodule"
) &&
(cd super &&
git submodule add ../submodule submodule &&
test_tick &&
git commit -m "submodule"
(
cd super &&
git submodule add ../submodule submodule &&
test_tick &&
git commit -m "submodule"
) &&
git clone super super-clone &&
(cd super-clone && git submodule update --init --recursive) &&
(
cd super-clone &&
git submodule update --init --recursive
) &&
git clone super empty-clone &&
(cd empty-clone && git submodule init) &&
(
cd empty-clone &&
git submodule init
) &&
git clone super top-only-clone &&
git clone super relative-clone &&
(cd relative-clone && git submodule update --init --recursive) &&
(
cd relative-clone &&
git submodule update --init --recursive
) &&
git clone super recursive-clone &&
(cd recursive-clone && git submodule update --init --recursive)
'
test_expect_success 'change submodule' '
(cd submodule &&
echo second line >> file &&
test_tick &&
git commit -a -m "change submodule"
(
cd recursive-clone &&
git submodule update --init --recursive
)
'
test_expect_success 'change submodule' '
(
cd submodule &&
echo second line >>file &&
test_tick &&
git commit -a -m "change submodule"
)
'
reset_submodule_urls () {
local root
root=$(pwd) &&
(
cd super-clone/submodule &&
git config remote.origin.url "$root/submodule"
) &&
(
cd super-clone/submodule/sub-submodule &&
git config remote.origin.url "$root/submodule"
)
}
test_expect_success 'change submodule url' '
(cd super &&
cd submodule &&
git checkout master &&
git pull
(
cd super &&
cd submodule &&
git checkout master &&
git pull
) &&
mv submodule moved-submodule &&
(cd moved-submodule &&
git config -f .gitmodules submodule.sub-submodule.url ../moved-submodule &&
test_tick &&
git commit -a -m moved-sub-submodule
(
cd moved-submodule &&
git config -f .gitmodules submodule.sub-submodule.url ../moved-submodule &&
test_tick &&
git commit -a -m moved-sub-submodule
) &&
(cd super &&
git config -f .gitmodules submodule.submodule.url ../moved-submodule &&
test_tick &&
git commit -a -m moved-submodule
(
cd super &&
git config -f .gitmodules submodule.submodule.url ../moved-submodule &&
test_tick &&
git commit -a -m moved-submodule
)
'
test_expect_success '"git submodule sync" should update submodule URLs' '
(cd super-clone &&
git pull --no-recurse-submodules &&
git submodule sync
(
cd super-clone &&
git pull --no-recurse-submodules &&
git submodule sync
) &&
test -d "$(cd super-clone/submodule &&
git config remote.origin.url
test -d "$(
cd super-clone/submodule &&
git config remote.origin.url
)" &&
test ! -d "$(cd super-clone/submodule/sub-submodule &&
git config remote.origin.url
test ! -d "$(
cd super-clone/submodule/sub-submodule &&
git config remote.origin.url
)" &&
(cd super-clone/submodule &&
git checkout master &&
git pull
(
cd super-clone/submodule &&
git checkout master &&
git pull
) &&
(cd super-clone &&
test -d "$(git config submodule.submodule.url)"
(
cd super-clone &&
test -d "$(git config submodule.submodule.url)"
)
'
test_expect_success '"git submodule sync --recursive" should update all submodule URLs' '
(cd super-clone &&
(cd submodule &&
git pull --no-recurse-submodules
) &&
git submodule sync --recursive
(
cd super-clone &&
(
cd submodule &&
git pull --no-recurse-submodules
) &&
git submodule sync --recursive
) &&
test -d "$(cd super-clone/submodule &&
git config remote.origin.url
test -d "$(
cd super-clone/submodule &&
git config remote.origin.url
)" &&
test -d "$(cd super-clone/submodule/sub-submodule &&
git config remote.origin.url
test -d "$(
cd super-clone/submodule/sub-submodule &&
git config remote.origin.url
)" &&
(cd super-clone/submodule/sub-submodule &&
git checkout master &&
git pull
(
cd super-clone/submodule/sub-submodule &&
git checkout master &&
git pull
)
'
test_expect_success 'reset submodule URLs' '
reset_submodule_urls super-clone
'
test_expect_success '"git submodule sync" should update submodule URLs - subdirectory' '
(
cd super-clone &&
git pull --no-recurse-submodules &&
mkdir -p sub &&
cd sub &&
git submodule sync >../../output
) &&
grep "\\.\\./submodule" output &&
test -d "$(
cd super-clone/submodule &&
git config remote.origin.url
)" &&
test ! -d "$(
cd super-clone/submodule/sub-submodule &&
git config remote.origin.url
)" &&
(
cd super-clone/submodule &&
git checkout master &&
git pull
) &&
(
cd super-clone &&
test -d "$(git config submodule.submodule.url)"
)
'
test_expect_success '"git submodule sync --recursive" should update all submodule URLs - subdirectory' '
(
cd super-clone &&
(
cd submodule &&
git pull --no-recurse-submodules
) &&
mkdir -p sub &&
cd sub &&
git submodule sync --recursive >../../output
) &&
grep "\\.\\./submodule/sub-submodule" output &&
test -d "$(
cd super-clone/submodule &&
git config remote.origin.url
)" &&
test -d "$(
cd super-clone/submodule/sub-submodule &&
git config remote.origin.url
)" &&
(
cd super-clone/submodule/sub-submodule &&
git checkout master &&
git pull
)
'
test_expect_success '"git submodule sync" should update known submodule URLs' '
(cd empty-clone &&
git pull &&
git submodule sync &&
test -d "$(git config submodule.submodule.url)"
(
cd empty-clone &&
git pull &&
git submodule sync &&
test -d "$(git config submodule.submodule.url)"
)
'
test_expect_success '"git submodule sync" should not vivify uninteresting submodule' '
(cd top-only-clone &&
git pull &&
git submodule sync &&
test -z "$(git config submodule.submodule.url)" &&
git submodule sync submodule &&
test -z "$(git config submodule.submodule.url)"
(
cd top-only-clone &&
git pull &&
git submodule sync &&
test -z "$(git config submodule.submodule.url)" &&
git submodule sync submodule &&
test -z "$(git config submodule.submodule.url)"
)
'
test_expect_success '"git submodule sync" handles origin URL of the form foo' '
(cd relative-clone &&
git remote set-url origin foo &&
git submodule sync &&
(cd submodule &&
#actual fails with: "cannot strip off url foo
test "$(git config remote.origin.url)" = "../submodule"
)
(
cd relative-clone &&
git remote set-url origin foo &&
git submodule sync &&
(
cd submodule &&
#actual fails with: "cannot strip off url foo
test "$(git config remote.origin.url)" = "../submodule"
)
)
'
test_expect_success '"git submodule sync" handles origin URL of the form foo/bar' '
(cd relative-clone &&
git remote set-url origin foo/bar &&
git submodule sync &&
(cd submodule &&
#actual foo/submodule
test "$(git config remote.origin.url)" = "../foo/submodule"
)
(cd submodule/sub-submodule &&
test "$(git config remote.origin.url)" != "../../foo/submodule"
)
(
cd relative-clone &&
git remote set-url origin foo/bar &&
git submodule sync &&
(
cd submodule &&
#actual foo/submodule
test "$(git config remote.origin.url)" = "../foo/submodule"
) &&
(
cd submodule/sub-submodule &&
test "$(git config remote.origin.url)" != "../../foo/submodule"
)
)
'
test_expect_success '"git submodule sync --recursive" propagates changes in origin' '
(cd recursive-clone &&
git remote set-url origin foo/bar &&
git submodule sync --recursive &&
(cd submodule &&
#actual foo/submodule
test "$(git config remote.origin.url)" = "../foo/submodule"
)
(cd submodule/sub-submodule &&
test "$(git config remote.origin.url)" = "../../foo/submodule"
)
(
cd recursive-clone &&
git remote set-url origin foo/bar &&
git submodule sync --recursive &&
(
cd submodule &&
#actual foo/submodule
test "$(git config remote.origin.url)" = "../foo/submodule"
) &&
(
cd submodule/sub-submodule &&
test "$(git config remote.origin.url)" = "../../foo/submodule"
)
)
'
test_expect_success '"git submodule sync" handles origin URL of the form ./foo' '
(cd relative-clone &&
git remote set-url origin ./foo &&
git submodule sync &&
(cd submodule &&
#actual ./submodule
test "$(git config remote.origin.url)" = "../submodule"
)
(
cd relative-clone &&
git remote set-url origin ./foo &&
git submodule sync &&
(
cd submodule &&
#actual ./submodule
test "$(git config remote.origin.url)" = "../submodule"
)
)
'
test_expect_success '"git submodule sync" handles origin URL of the form ./foo/bar' '
(cd relative-clone &&
git remote set-url origin ./foo/bar &&
git submodule sync &&
(cd submodule &&
#actual ./foo/submodule
test "$(git config remote.origin.url)" = "../foo/submodule"
)
(
cd relative-clone &&
git remote set-url origin ./foo/bar &&
git submodule sync &&
(
cd submodule &&
#actual ./foo/submodule
test "$(git config remote.origin.url)" = "../foo/submodule"
)
)
'
test_expect_success '"git submodule sync" handles origin URL of the form ../foo' '
(cd relative-clone &&
git remote set-url origin ../foo &&
git submodule sync &&
(cd submodule &&
#actual ../submodule
test "$(git config remote.origin.url)" = "../../submodule"
)
(
cd relative-clone &&
git remote set-url origin ../foo &&
git submodule sync &&
(
cd submodule &&
#actual ../submodule
test "$(git config remote.origin.url)" = "../../submodule"
)
)
'
test_expect_success '"git submodule sync" handles origin URL of the form ../foo/bar' '
(cd relative-clone &&
git remote set-url origin ../foo/bar &&
git submodule sync &&
(cd submodule &&
#actual ../foo/submodule
test "$(git config remote.origin.url)" = "../../foo/submodule"
)
(
cd relative-clone &&
git remote set-url origin ../foo/bar &&
git submodule sync &&
(
cd submodule &&
#actual ../foo/submodule
test "$(git config remote.origin.url)" = "../../foo/submodule"
)
)
'
test_expect_success '"git submodule sync" handles origin URL of the form ../foo/bar with deeply nested submodule' '
(cd relative-clone &&
git remote set-url origin ../foo/bar &&
mkdir -p a/b/c &&
( cd a/b/c &&
git init &&
:> .gitignore &&
git add .gitignore &&
test_tick &&
git commit -m "initial commit" ) &&
git submodule add ../bar/a/b/c ./a/b/c &&
git submodule sync &&
(cd a/b/c &&
#actual ../foo/bar/a/b/c
test "$(git config remote.origin.url)" = "../../../../foo/bar/a/b/c"
)
(
cd relative-clone &&
git remote set-url origin ../foo/bar &&
mkdir -p a/b/c &&
(
cd a/b/c &&
git init &&
>.gitignore &&
git add .gitignore &&
test_tick &&
git commit -m "initial commit"
) &&
git submodule add ../bar/a/b/c ./a/b/c &&
git submodule sync &&
(
cd a/b/c &&
#actual ../foo/bar/a/b/c
test "$(git config remote.origin.url)" = "../../../../foo/bar/a/b/c"
)
)
'

Просмотреть файл

@ -80,6 +80,21 @@ test_expect_success 'submodule update detaching the HEAD ' '
)
'
test_expect_success 'submodule update from subdirectory' '
(cd super/submodule &&
git reset --hard HEAD~1
) &&
mkdir super/sub &&
(cd super/sub &&
(cd ../submodule &&
compare_head
) &&
git submodule update ../submodule &&
cd ../submodule &&
! compare_head
)
'
apos="'";
test_expect_success 'submodule update does not fetch already present commits' '
(cd submodule &&

Просмотреть файл

@ -80,6 +80,22 @@ test_expect_success 'test basic "submodule foreach" usage' '
test_i18ncmp expect actual
'
cat >expect <<EOF
Entering '../sub1'
$pwd/clone-foo1-../sub1-$sub1sha1
Entering '../sub3'
$pwd/clone-foo3-../sub3-$sub3sha1
EOF
test_expect_success 'test "submodule foreach" from subdirectory' '
mkdir clone/sub &&
(
cd clone/sub &&
git submodule foreach "echo \$toplevel-\$name-\$sm_path-\$sha1" >../../actual
) &&
test_i18ncmp expect actual
'
test_expect_success 'setup nested submodules' '
git clone submodule nested1 &&
git clone submodule nested2 &&