summaryrefslogtreecommitdiff
path: root/git-submodule.sh
diff options
context:
space:
mode:
Diffstat (limited to 'git-submodule.sh')
-rwxr-xr-xgit-submodule.sh59
1 files changed, 29 insertions, 30 deletions
diff --git a/git-submodule.sh b/git-submodule.sh
index 8b5ad59bde..b5f2beee60 100755
--- a/git-submodule.sh
+++ b/git-submodule.sh
@@ -72,7 +72,7 @@ get_submodule_config () {
value=$(git config submodule."$name"."$option")
if test -z "$value"
then
- value=$(git config -f .gitmodules submodule."$name"."$option")
+ value=$(git submodule--helper config submodule."$name"."$option")
fi
printf '%s' "${value:-$default}"
}
@@ -82,6 +82,11 @@ isnumber()
n=$(($1 + 0)) 2>/dev/null && test "$n" = "$1"
}
+# Given a full hex object ID, is this the zero OID?
+is_zero_oid () {
+ echo "$1" | sane_egrep '^0+$' >/dev/null 2>&1
+}
+
# Sanitize the local git environment for use within a submodule. We
# can't simply use clear_local_git_env since we want to preserve some
# of the settings from GIT_CONFIG_PARAMETERS.
@@ -159,6 +164,11 @@ cmd_add()
shift
done
+ if ! git submodule--helper config --check-writeable >/dev/null 2>&1
+ then
+ die "$(eval_gettext "please make sure that the .gitmodules file is in the working tree")"
+ fi
+
if test -n "$reference_path"
then
is_absolute_path "$reference_path" ||
@@ -283,11 +293,11 @@ or you are unsure what this means choose another name with the '--name' option."
git add --no-warn-embedded-repo $force "$sm_path" ||
die "$(eval_gettext "Failed to add submodule '\$sm_path'")"
- git config -f .gitmodules submodule."$sm_name".path "$sm_path" &&
- git config -f .gitmodules submodule."$sm_name".url "$repo" &&
+ git submodule--helper config submodule."$sm_name".path "$sm_path" &&
+ git submodule--helper config submodule."$sm_name".url "$repo" &&
if test -n "$branch"
then
- git config -f .gitmodules submodule."$sm_name".branch "$branch"
+ git submodule--helper config submodule."$sm_name".branch "$branch"
fi &&
git add --force .gitmodules ||
die "$(eval_gettext "Failed to register submodule '\$sm_path'")"
@@ -438,6 +448,9 @@ cmd_update()
-q|--quiet)
GIT_QUIET=1
;;
+ -v)
+ GIT_QUIET=0
+ ;;
--progress)
progress=1
;;
@@ -531,31 +544,19 @@ cmd_update()
"$@" || echo "#unmatched" $?
} | {
err=
- while read -r mode sha1 stage just_cloned sm_path
+ while read -r quickabort sha1 just_cloned sm_path
do
- die_if_unmatched "$mode" "$sha1"
+ die_if_unmatched "$quickabort" "$sha1"
- name=$(git submodule--helper name "$sm_path") || exit
- if ! test -z "$update"
- then
- update_module=$update
- else
- update_module=$(git config submodule."$name".update)
- if test -z "$update_module"
- then
- update_module="checkout"
- fi
- fi
+ git submodule--helper ensure-core-worktree "$sm_path" || exit 1
+
+ update_module=$(git submodule--helper update-module-mode $just_cloned "$sm_path" $update)
displaypath=$(git submodule--helper relative-path "$prefix$sm_path" "$wt_prefix")
if test $just_cloned -eq 1
then
subsha1=
- case "$update_module" in
- merge | rebase | none)
- update_module=checkout ;;
- esac
else
subsha1=$(sanitize_submodule_env; cd "$sm_path" &&
git rev-parse --verify HEAD) ||
@@ -577,11 +578,6 @@ cmd_update()
die "$(eval_gettext "Unable to find current \${remote_name}/\${branch} revision in submodule path '\$sm_path'")"
fi
- if ! $(git config -f "$(git rev-parse --git-common-dir)/modules/$name/config" core.worktree) 2>/dev/null
- then
- git submodule--helper connect-gitdir-workingtree "$name" "$sm_path"
- fi
-
if test "$subsha1" != "$sha1" || test -n "$force"
then
subforce=$force
@@ -632,7 +628,7 @@ cmd_update()
must_die_on_failure=yes
;;
*)
- die "$(eval_gettext "Invalid update mode '$update_module' for submodule '$name'")"
+ die "$(eval_gettext "Invalid update mode '$update_module' for submodule path '$path'")"
esac
if (sanitize_submodule_env; cd "$sm_path" && $command "$sha1")
@@ -794,7 +790,7 @@ cmd_summary() {
while read -r mod_src mod_dst sha1_src sha1_dst status name
do
if test -z "$cached" &&
- test $sha1_dst = 0000000000000000000000000000000000000000
+ is_zero_oid $sha1_dst
then
case "$mod_dst" in
160000)
@@ -854,8 +850,11 @@ cmd_summary() {
;;
esac
- sha1_abbr_src=$(echo $sha1_src | cut -c1-7)
- sha1_abbr_dst=$(echo $sha1_dst | cut -c1-7)
+ sha1_abbr_src=$(GIT_DIR="$name/.git" git rev-parse --short $sha1_src 2>/dev/null ||
+ echo $sha1_src | cut -c1-7)
+ sha1_abbr_dst=$(GIT_DIR="$name/.git" git rev-parse --short $sha1_dst 2>/dev/null ||
+ echo $sha1_dst | cut -c1-7)
+
if test $status = T
then
blob="$(gettext "blob")"