Merge branch 'sb/submodule-update-initial-runs-custom-script'
authorJunio C Hamano <gitster@pobox.com>
Fri, 3 Feb 2017 19:25:19 +0000 (11:25 -0800)
committerJunio C Hamano <gitster@pobox.com>
Fri, 3 Feb 2017 19:25:19 +0000 (11:25 -0800)
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

1  2 
git-submodule.sh
t/t7406-submodule-update.sh
diff --combined git-submodule.sh
index 123ac104c6f312cc27f1ddf925c80b386bfd4f23,f1d3324be908c330657a8a438b466e54e2295fdb..136e26a2c8d4ca1e835e2873f3fd994864dc135e
@@@ -12,8 -12,7 +12,8 @@@ USAGE="[--quiet] add [-b <branch>] [-f|
     or: $dashless [--quiet] update [--init] [--remote] [-N|--no-fetch] [-f|--force] [--checkout|--merge|--rebase] [--[no-]recommend-shallow] [--reference <repository>] [--recursive] [--] [<path>...]
     or: $dashless [--quiet] summary [--cached|--files] [--summary-limit <n>] [commit] [--] [<path>...]
     or: $dashless [--quiet] foreach [--recursive] <command>
 -   or: $dashless [--quiet] sync [--recursive] [--] [<path>...]"
 +   or: $dashless [--quiet] sync [--recursive] [--] [<path>...]
 +   or: $dashless [--quiet] absorbgitdirs [--] [<path>...]"
  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
                        ;;
  
        {
        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} \
                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.
  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)
index 725bbed1f866265e8030ab6e4007c04f9493b6b5,8c086a429b8253871b652265390ff6ba47c7074d..347857fa7c7cb12a4bc9fd6a2f5373347a02db5c
@@@ -140,23 -140,6 +140,23 @@@ test_expect_success 'submodule update -
        test_i18ncmp expect2 actual2
  '
  
 +cat <<EOF >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 &&
  '
  
  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 &&