From: Junio C Hamano Date: Fri, 3 Feb 2017 19:25:19 +0000 (-0800) Subject: Merge branch 'sb/submodule-update-initial-runs-custom-script' X-Git-Tag: v2.12.0-rc0~5 X-Git-Url: https://git.lorimer.id.au/gitweb.git/diff_plain/4ba6bb2d1792bd799b295b879461ee5453faab3e?ds=inline;hp=-c Merge branch 'sb/submodule-update-initial-runs-custom-script' The user can specify a custom update method that is run when "submodule update" updates an already checked out submodule. This was ignored when checking the submodule out for the first time and we instead always just checked out the commit that is bound to the path in the superproject's index. * sb/submodule-update-initial-runs-custom-script: submodule update: run custom update script for initial populating as well --- 4ba6bb2d1792bd799b295b879461ee5453faab3e diff --combined git-submodule.sh index 123ac104c6,f1d3324be9..136e26a2c8 --- a/git-submodule.sh +++ b/git-submodule.sh @@@ -12,8 -12,7 +12,8 @@@ USAGE="[--quiet] add [-b ] [-f| or: $dashless [--quiet] update [--init] [--remote] [-N|--no-fetch] [-f|--force] [--checkout|--merge|--rebase] [--[no-]recommend-shallow] [--reference ] [--recursive] [--] [...] or: $dashless [--quiet] summary [--cached|--files] [--summary-limit ] [commit] [--] [...] or: $dashless [--quiet] foreach [--recursive] - or: $dashless [--quiet] sync [--recursive] [--] [...]" + or: $dashless [--quiet] sync [--recursive] [--] [...] + or: $dashless [--quiet] absorbgitdirs [--] [...]" OPTIONS_SPEC= SUBDIRECTORY_OK=Yes . git-sh-setup @@@ -22,10 -21,14 +22,10 @@@ require_work_tre wt_prefix=$(git rev-parse --show-prefix) cd_to_toplevel -# Restrict ourselves to a vanilla subset of protocols; the URLs -# we get are under control of a remote repository, and we do not -# want them kicking off arbitrary git-remote-* programs. -# -# If the user has already specified a set of allowed protocols, -# we assume they know what they're doing and use that instead. -: ${GIT_ALLOW_PROTOCOL=file:git:http:https:ssh} -export GIT_ALLOW_PROTOCOL +# Tell the rest of git that any URLs we get don't come +# directly from the user, so it can apply policy as appropriate. +GIT_PROTOCOL_FROM_USER=0 +export GIT_PROTOCOL_FROM_USER command= branch= @@@ -41,7 -44,6 +41,7 @@@ update prefix= custom_name= depth= +progress= die_if_unmatched () { @@@ -204,14 -206,8 +204,14 @@@ cmd_add( tstart s|/*$|| ') - git ls-files --error-unmatch "$sm_path" > /dev/null 2>&1 && - die "$(eval_gettext "'\$sm_path' already exists in the index")" + if test -z "$force" + then + git ls-files --error-unmatch "$sm_path" > /dev/null 2>&1 && + die "$(eval_gettext "'\$sm_path' already exists in the index")" + else + git ls-files -s "$sm_path" | sane_grep -v "^160000" > /dev/null 2>&1 && + die "$(eval_gettext "'\$sm_path' already exists in the index and is not a submodule")" + fi if test -z "$force" && ! git add --dry-run --ignore-missing "$sm_path" > /dev/null 2>&1 then @@@ -377,7 -373,7 +377,7 @@@ cmd_init( shift done - git ${wt_prefix:+-C "$wt_prefix"} submodule--helper init ${GIT_QUIET:+--quiet} ${prefix:+--prefix "$prefix"} "$@" + git ${wt_prefix:+-C "$wt_prefix"} ${prefix:+--super-prefix "$prefix"} submodule--helper init ${GIT_QUIET:+--quiet} "$@" } # @@@ -502,9 -498,6 +502,9 @@@ cmd_update( -q|--quiet) GIT_QUIET=1 ;; + --progress) + progress="--progress" + ;; -i|--init) init=1 ;; @@@ -580,11 -573,10 +580,11 @@@ { git submodule--helper update-clone ${GIT_QUIET:+--quiet} \ + ${progress:+"$progress"} \ ${wt_prefix:+--prefix "$wt_prefix"} \ ${prefix:+--recursive-prefix "$prefix"} \ ${update:+--update "$update"} \ - ${reference:+--reference "$reference"} \ + ${reference:+"$reference"} \ ${depth:+--depth "$depth"} \ ${recommend_shallow:+"$recommend_shallow"} \ ${jobs:+$jobs} \ @@@ -613,7 -605,10 +613,10 @@@ if test $just_cloned -eq 1 then subsha1= - update_module=checkout + case "$update_module" in + merge | rebase | none) + update_module=checkout ;; + esac else subsha1=$(sanitize_submodule_env; cd "$sm_path" && git rev-parse --verify HEAD) || @@@ -1134,11 -1129,6 +1137,11 @@@ cmd_sync( done } +cmd_absorbgitdirs() +{ + git submodule--helper absorb-git-dirs --prefix "$wt_prefix" "$@" +} + # This loop parses the command line arguments to find the # subcommand name to dispatch. Parsing of the subcommand specific # options are primarily done by the subcommand implementations. @@@ -1148,7 -1138,7 +1151,7 @@@ while test $# != 0 && test -z "$command" do case "$1" in - add | foreach | init | deinit | update | status | summary | sync) + add | foreach | init | deinit | update | status | summary | sync | absorbgitdirs) command=$1 ;; -q|--quiet) diff --combined t/t7406-submodule-update.sh index 725bbed1f8,8c086a429b..347857fa7c --- a/t/t7406-submodule-update.sh +++ b/t/t7406-submodule-update.sh @@@ -140,23 -140,6 +140,23 @@@ test_expect_success 'submodule update - test_i18ncmp expect2 actual2 ' +cat <expect2 +Submodule 'foo/sub' ($pwd/withsubs/../rebasing) registered for path 'sub' +EOF + +test_expect_success 'submodule update --init from and of subdirectory' ' + git init withsubs && + (cd withsubs && + mkdir foo && + git submodule add "$(pwd)/../rebasing" foo/sub && + (cd foo && + git submodule deinit -f sub && + git submodule update --init sub 2>../../actual2 + ) + ) && + test_i18ncmp expect2 actual2 +' + apos="'"; test_expect_success 'submodule update does not fetch already present commits' ' (cd submodule && @@@ -441,6 -424,16 +441,16 @@@ test_expect_success 'submodule update test_i18ncmp actual expect ' + test_expect_success 'submodule update - command run for initial population of submodule' ' + cat <<-\ EOF >expect + Execution of '\''false $submodulesha1'\'' failed in submodule path '\''submodule'\'' + EOF && + rm -rf super/submodule && + test_must_fail git -C super submodule update >../actual && + test_cmp expect actual && + git -C super submodule update --checkout + ' + cat << EOF >expect Execution of 'false $submodulesha1' failed in submodule path '../super/submodule' Failed to recurse into submodule path '../super' @@@ -493,6 -486,7 +503,7 @@@ test_expect_success 'submodule init pic ' test_expect_success 'submodule update --merge - ignores --merge for new submodules' ' + test_config -C super submodule.submodule.update checkout && (cd super && rm -rf submodule && git submodule update submodule && @@@ -505,6 -499,7 +516,7 @@@ ' test_expect_success 'submodule update --rebase - ignores --rebase for new submodules' ' + test_config -C super submodule.submodule.update checkout && (cd super && rm -rf submodule && git submodule update submodule &&