diff options
Diffstat (limited to 'git-submodule.sh')
-rwxr-xr-x | git-submodule.sh | 138 |
1 files changed, 48 insertions, 90 deletions
diff --git a/git-submodule.sh b/git-submodule.sh index 136e26a2c8..156255a9e5 100755 --- a/git-submodule.sh +++ b/git-submodule.sh @@ -213,7 +213,8 @@ cmd_add() 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 + if test -z "$force" && + ! git add --dry-run --ignore-missing --no-warn-embedded-repo "$sm_path" > /dev/null 2>&1 then eval_gettextln "The following path is ignored by one of your .gitignore files: \$sm_path @@ -267,7 +268,7 @@ or you are unsure what this means choose another name with the '--name' option." fi git config submodule."$sm_name".url "$realrepo" - git add $force "$sm_path" || + 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" && @@ -278,6 +279,20 @@ or you are unsure what this means choose another name with the '--name' option." fi && git add --force .gitmodules || die "$(eval_gettext "Failed to register submodule '\$sm_path'")" + + # NEEDSWORK: In a multi-working-tree world, this needs to be + # set in the per-worktree config. + if git config --get submodule.active >/dev/null + then + # If the submodule being adding isn't already covered by the + # current configured pathspec, set the submodule's active flag + if ! git submodule--helper is-active "$sm_path" + then + git config submodule."$sm_name".active "true" + fi + else + git config submodule."$sm_name".active "true" + fi } # @@ -318,7 +333,7 @@ cmd_foreach() git submodule--helper list --prefix "$wt_prefix" || echo "#unmatched" $? } | - while read mode sha1 stage sm_path + while read -r mode sha1 stage sm_path do die_if_unmatched "$mode" "$sha1" if test -e "$sm_path"/.git @@ -427,7 +442,7 @@ cmd_deinit() git submodule--helper list --prefix "$wt_prefix" "$@" || echo "#unmatched" $? } | - while read mode sha1 stage sm_path + while read -r mode sha1 stage sm_path do die_if_unmatched "$mode" "$sha1" name=$(git submodule--helper name "$sm_path") || exit @@ -591,12 +606,11 @@ cmd_update() "$@" || echo "#unmatched" $? } | { err= - while read mode sha1 stage just_cloned sm_path + while read -r mode sha1 stage just_cloned sm_path do die_if_unmatched "$mode" "$sha1" name=$(git submodule--helper name "$sm_path") || exit - url=$(git config submodule."$name".url) if ! test -z "$update" then update_module=$update @@ -744,18 +758,6 @@ cmd_update() } } -set_name_rev () { - revname=$( ( - sanitize_submodule_env - cd "$1" && { - git describe "$2" 2>/dev/null || - git describe --tags "$2" 2>/dev/null || - git describe --contains "$2" 2>/dev/null || - git describe --all --always "$2" - } - ) ) - test -z "$revname" || revname=" ($revname)" -} # # Show commit summary for submodules in index or working tree # @@ -833,7 +835,7 @@ cmd_summary() { # Get modified modules cared by user modules=$(git $diff_cmd $cached --ignore-submodules=dirty --raw $head -- "$@" | sane_egrep '^:([0-7]* )?160000' | - while read mod_src mod_dst sha1_src sha1_dst status sm_path + while read -r mod_src mod_dst sha1_src sha1_dst status sm_path do # Always show modules deleted or type-changed (blob<->module) if test "$status" = D || test "$status" = T @@ -849,7 +851,7 @@ cmd_summary() { test $status != A && test $ignore_config = all && continue fi # Also show added or modified modules which are checked out - GIT_DIR="$sm_path/.git" git-rev-parse --git-dir >/dev/null 2>&1 && + GIT_DIR="$sm_path/.git" git rev-parse --git-dir >/dev/null 2>&1 && printf '%s\n' "$sm_path" done ) @@ -859,7 +861,7 @@ cmd_summary() { git $diff_cmd $cached --ignore-submodules=dirty --raw $head -- $modules | sane_egrep '^:([0-7]* )?160000' | cut -c2- | - while read mod_src mod_dst sha1_src sha1_dst status name + while read -r mod_src mod_dst sha1_src sha1_dst status name do if test -z "$cached" && test $sha1_dst = 0000000000000000000000000000000000000000 @@ -883,11 +885,11 @@ cmd_summary() { missing_dst= test $mod_src = 160000 && - ! GIT_DIR="$name/.git" git-rev-parse -q --verify $sha1_src^0 >/dev/null && + ! GIT_DIR="$name/.git" git rev-parse -q --verify $sha1_src^0 >/dev/null && missing_src=t test $mod_dst = 160000 && - ! GIT_DIR="$name/.git" git-rev-parse -q --verify $sha1_dst^0 >/dev/null && + ! GIT_DIR="$name/.git" git rev-parse -q --verify $sha1_dst^0 >/dev/null && missing_dst=t display_name=$(git submodule--helper relative-path "$name" "$wt_prefix") @@ -1002,55 +1004,7 @@ cmd_status() shift done - { - git submodule--helper list --prefix "$wt_prefix" "$@" || - echo "#unmatched" $? - } | - while read mode sha1 stage sm_path - do - die_if_unmatched "$mode" "$sha1" - name=$(git submodule--helper name "$sm_path") || exit - url=$(git config submodule."$name".url) - displaypath=$(git submodule--helper relative-path "$prefix$sm_path" "$wt_prefix") - if test "$stage" = U - then - say "U$sha1 $displaypath" - continue - fi - if test -z "$url" || - { - ! test -d "$sm_path"/.git && - ! test -f "$sm_path"/.git - } - then - say "-$sha1 $displaypath" - continue; - fi - if git diff-files --ignore-submodules=dirty --quiet -- "$sm_path" - then - set_name_rev "$sm_path" "$sha1" - say " $sha1 $displaypath$revname" - else - if test -z "$cached" - then - sha1=$(sanitize_submodule_env; cd "$sm_path" && git rev-parse --verify HEAD) - fi - set_name_rev "$sm_path" "$sha1" - say "+$sha1 $displaypath$revname" - fi - - if test -n "$recursive" - then - ( - prefix="$displaypath/" - sanitize_submodule_env - wt_prefix= - cd "$sm_path" && - eval cmd_status - ) || - die "$(eval_gettext "Failed to recurse into submodule path '\$sm_path'")" - fi - done + git ${wt_prefix:+-C "$wt_prefix"} ${prefix:+--super-prefix "$prefix"} submodule--helper status ${GIT_QUIET:+--quiet} ${cached:+--cached} ${recursive:+--recursive} "$@" } # # Sync remote urls for submodules @@ -1087,9 +1041,16 @@ cmd_sync() git submodule--helper list --prefix "$wt_prefix" "$@" || echo "#unmatched" $? } | - while read mode sha1 stage sm_path + while read -r mode sha1 stage sm_path do die_if_unmatched "$mode" "$sha1" + + # skip inactive submodules + if ! git submodule--helper is-active "$sm_path" + then + continue + fi + name=$(git submodule--helper name "$sm_path") url=$(git config -f .gitmodules --get submodule."$name".url) @@ -1112,27 +1073,24 @@ cmd_sync() ;; esac - if git config "submodule.$name.url" >/dev/null 2>/dev/null + displaypath=$(git submodule--helper relative-path "$prefix$sm_path" "$wt_prefix") + say "$(eval_gettext "Synchronizing submodule url for '\$displaypath'")" + git config submodule."$name".url "$super_config_url" + + if test -e "$sm_path"/.git then - displaypath=$(git submodule--helper relative-path "$prefix$sm_path" "$wt_prefix") - say "$(eval_gettext "Synchronizing submodule url for '\$displaypath'")" - git config submodule."$name".url "$super_config_url" + ( + sanitize_submodule_env + cd "$sm_path" + remote=$(get_default_remote) + git config remote."$remote".url "$sub_origin_url" - if test -e "$sm_path"/.git + if test -n "$recursive" then - ( - sanitize_submodule_env - cd "$sm_path" - remote=$(get_default_remote) - git config remote."$remote".url "$sub_origin_url" - - if test -n "$recursive" - then - prefix="$prefix$sm_path/" - eval cmd_sync - fi - ) + prefix="$prefix$sm_path/" + eval cmd_sync fi + ) fi done } |