Merge branch 'we/submodule-update-prefix-output' into maint
authorJunio C Hamano <gitster@pobox.com>
Tue, 26 Mar 2013 19:44:26 +0000 (12:44 -0700)
committerJunio C Hamano <gitster@pobox.com>
Tue, 26 Mar 2013 19:44:27 +0000 (12:44 -0700)
"git submodule update", when recursed into sub-submodules, did not
acccumulate the prefix paths.

* we/submodule-update-prefix-output:
submodule update: when using recursion, show full path

1  2 
git-submodule.sh
t/t7406-submodule-update.sh
diff --combined git-submodule.sh
index 004c034bc09449416ff6d66b7570d48b651f96cb,f2c53c9a02d84ae4ecd0f465388d26febfcae519..ab29bfeb738d1b8f452c558ba6f6d7aa4e854b3d
@@@ -8,7 -8,7 +8,7 @@@ dashless=$(basename "$0" | sed -e 's/-
  USAGE="[--quiet] add [-b <branch>] [-f|--force] [--name <name>] [--reference <repository>] [--] <repository> [<path>]
     or: $dashless [--quiet] status [--cached] [--recursive] [--] [<path>...]
     or: $dashless [--quiet] init [--] [<path>...]
 -   or: $dashless [--quiet] update [--init] [-N|--no-fetch] [-f|--force] [--rebase] [--reference <repository>] [--merge] [--recursive] [--] [<path>...]
 +   or: $dashless [--quiet] update [--init] [--remote] [-N|--no-fetch] [-f|--force] [--rebase] [--reference <repository>] [--merge] [--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>...]"
@@@ -26,7 -26,6 +26,7 @@@ cached
  recursive=
  init=
  files=
 +remote=
  nofetch=
  update=
  prefix=
@@@ -153,32 -152,6 +153,32 @@@ die_if_unmatched (
        fi
  }
  
 +#
 +# Print a submodule configuration setting
 +#
 +# $1 = submodule name
 +# $2 = option name
 +# $3 = default value
 +#
 +# Checks in the usual git-config places first (for overrides),
 +# otherwise it falls back on .gitmodules.  This allows you to
 +# distribute project-wide defaults in .gitmodules, while still
 +# customizing individual repositories if necessary.  If the option is
 +# not in .gitmodules either, print a default value.
 +#
 +get_submodule_config () {
 +      name="$1"
 +      option="$2"
 +      default="$3"
 +      value=$(git config submodule."$name"."$option")
 +      if test -z "$value"
 +      then
 +              value=$(git config -f .gitmodules submodule."$name"."$option")
 +      fi
 +      printf '%s' "${value:-$default}"
 +}
 +
 +
  #
  # Map submodule path to submodule name
  #
@@@ -417,10 -390,6 +417,10 @@@ Use -f if you really want to add it." >
  
        git config -f .gitmodules submodule."$sm_name".path "$sm_path" &&
        git config -f .gitmodules submodule."$sm_name".url "$repo" &&
 +      if test -n "$branch"
 +      then
 +              git config -f .gitmodules submodule."$sm_name".branch "$branch"
 +      fi &&
        git add --force .gitmodules ||
        die "$(eval_gettext "Failed to register submodule '\$sm_path'")"
  }
@@@ -564,9 -533,6 +564,9 @@@ cmd_update(
                -i|--init)
                        init=1
                        ;;
 +              --remote)
 +                      remote=1
 +                      ;;
                -N|--no-fetch)
                        nofetch=1
                        ;;
                die_if_unmatched "$mode"
                if test "$stage" = U
                then
-                       echo >&2 "Skipping unmerged submodule $sm_path"
+                       echo >&2 "Skipping unmerged submodule $prefix$sm_path"
                        continue
                fi
                name=$(module_name "$sm_path") || exit
                url=$(git config submodule."$name".url)
 +              branch=$(get_submodule_config "$name" branch master)
                if ! test -z "$update"
                then
                        update_module=$update
  
                if test "$update_module" = "none"
                then
-                       echo "Skipping submodule '$sm_path'"
+                       echo "Skipping submodule '$prefix$sm_path'"
                        continue
                fi
  
                        # Only mention uninitialized submodules when its
                        # path have been specified
                        test "$#" != "0" &&
-                       say "$(eval_gettext "Submodule path '\$sm_path' not initialized
+                       say "$(eval_gettext "Submodule path '\$prefix\$sm_path' not initialized
  Maybe you want to use 'update --init'?")"
                        continue
                fi
                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 '\$sm_path'")"
+                       die "$(eval_gettext "Unable to find current revision in submodule path '\$prefix\$sm_path'")"
                fi
  
 +              if test -n "$remote"
 +              then
 +                      if test -z "$nofetch"
 +                      then
 +                              # Fetch remote before determining tracking $sha1
 +                              (clear_local_git_env; cd "$sm_path" && git-fetch) ||
 +                              die "$(eval_gettext "Unable to fetch in submodule path '\$sm_path'")"
 +                      fi
 +                      remote_name=$(clear_local_git_env; cd "$sm_path" && get_default_remote)
 +                      sha1=$(clear_local_git_env; cd "$sm_path" &&
 +                              git rev-parse --verify "${remote_name}/${branch}") ||
 +                      die "$(eval_gettext "Unable to find current ${remote_name}/${branch} revision in submodule path '\$sm_path'")"
 +              fi
 +
                if test "$subsha1" != "$sha1" -o -n "$force"
                then
                        subforce=$force
                                (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 '\$sm_path'")"
+                               die "$(eval_gettext "Unable to fetch in submodule path '\$prefix\$sm_path'")"
                        fi
  
                        # Is this something we just cloned?
                        case "$update_module" in
                        rebase)
                                command="git rebase"
-                               die_msg="$(eval_gettext "Unable to rebase '\$sha1' in submodule path '\$sm_path'")"
-                               say_msg="$(eval_gettext "Submodule path '\$sm_path': rebased into '\$sha1'")"
+                               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'")"
                                must_die_on_failure=yes
                                ;;
                        merge)
                                command="git merge"
-                               die_msg="$(eval_gettext "Unable to merge '\$sha1' in submodule path '\$sm_path'")"
-                               say_msg="$(eval_gettext "Submodule path '\$sm_path': merged in '\$sha1'")"
+                               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'")"
                                must_die_on_failure=yes
                                ;;
                        *)
                                command="git checkout $subforce -q"
-                               die_msg="$(eval_gettext "Unable to checkout '\$sha1' in submodule path '\$sm_path'")"
-                               say_msg="$(eval_gettext "Submodule path '\$sm_path': checked out '\$sha1'")"
+                               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'")"
                                ;;
                        esac
  
  
                if test -n "$recursive"
                then
-                       (clear_local_git_env; cd "$sm_path" && eval cmd_update "$orig_flags")
+                       (
+                               prefix="$prefix$sm_path/"
+                               clear_local_git_env
+                               cd "$sm_path" &&
+                               eval cmd_update "$orig_flags"
+                       )
                        res=$?
                        if test $res -gt 0
                        then
-                               die_msg="$(eval_gettext "Failed to recurse into submodule path '\$sm_path'")"
+                               die_msg="$(eval_gettext "Failed to recurse into submodule path '\$prefix\$sm_path'")"
                                if test $res -eq 1
                                then
                                        err="${err};$die_msg"
@@@ -976,12 -932,12 +981,12 @@@ cmd_summary() 
        done |
        if test -n "$for_status"; then
                if [ -n "$files" ]; then
 -                      gettextln "# Submodules changed but not updated:"
 +                      gettextln "Submodules changed but not updated:" | git stripspace -c
                else
 -                      gettextln "# Submodule changes to be committed:"
 +                      gettextln "Submodule changes to be committed:" | git stripspace -c
                fi
 -              echo "#"
 -              sed -e 's|^|# |' -e 's|^# $|#|'
 +              printf "\n" | git stripspace -c
 +              git stripspace -c
        else
                cat
        fi
index 4975ec07ce614c8473f7f5638a008d7058730f06,70528b7e1520bdcd9480a20ac5a993ba96c80ce8..1a3d20bdc36c63c5261090d76858d43bd7f64113
@@@ -135,37 -135,6 +135,37 @@@ test_expect_success 'submodule update -
        )
  '
  
 +test_expect_success 'submodule update --remote should fetch upstream changes' '
 +      (cd submodule &&
 +       echo line4 >> file &&
 +       git add file &&
 +       test_tick &&
 +       git commit -m "upstream line4"
 +      ) &&
 +      (cd super &&
 +       git submodule update --remote --force submodule &&
 +       cd submodule &&
 +       test "$(git log -1 --oneline)" = "$(GIT_DIR=../../submodule/.git git log -1 --oneline)"
 +      )
 +'
 +
 +test_expect_success 'local config should override .gitmodules branch' '
 +      (cd submodule &&
 +       git checkout -b test-branch &&
 +       echo line5 >> file &&
 +       git add file &&
 +       test_tick &&
 +       git commit -m "upstream line5" &&
 +       git checkout master
 +      ) &&
 +      (cd super &&
 +       git config submodule.submodule.branch test-branch &&
 +       git submodule update --remote --force submodule &&
 +       cd submodule &&
 +       test "$(git log -1 --oneline)" = "$(GIT_DIR=../../submodule/.git git log -1 --oneline test-branch)"
 +      )
 +'
 +
  test_expect_success 'submodule update --rebase staying on master' '
        (cd super/submodule &&
          git checkout master
@@@ -643,7 -612,8 +643,8 @@@ test_expect_success 'submodule update p
        rm -rf super_update_r2 &&
        git clone super_update_r super_update_r2 &&
        (cd super_update_r2 &&
-        git submodule update --init --recursive &&
+        git submodule update --init --recursive >actual &&
+        test_i18ngrep "Submodule path .submodule/subsubmodule.: checked out" actual &&
         (cd submodule/subsubmodule &&
          git log > ../../expected
         ) &&