X-Git-Url: http://git.tremily.us/?a=blobdiff_plain;f=git-submodule.sh;h=d9a59af1001d9fd527594f3e94f4c702e9cbc24b;hb=refs%2Fheads%2Fwtk%2Fsubmodule-commit;hp=3e2045e52daf43cc351af23af0fd770fb1a5044f;hpb=cfade4c0be2d02da91db95c4ea6fac7663139d1d;p=git.git diff --git a/git-submodule.sh b/git-submodule.sh index 3e2045e52..d9a59af10 100755 --- a/git-submodule.sh +++ b/git-submodule.sh @@ -8,7 +8,7 @@ dashless=$(basename "$0" | sed -e 's/-/ /') USAGE="[--quiet] add [-b branch] [-f|--force] [--reference ] [--] [] or: $dashless [--quiet] status [--cached] [--recursive] [--] [...] or: $dashless [--quiet] init [--] [...] - or: $dashless [--quiet] update [--init] [-N|--no-fetch] [-f|--force] [--rebase] [--reference ] [--merge] [--recursive] [--] [...] + or: $dashless [--quiet] update [--init] [-N|--no-fetch] [-f|--force] [--commit] [--rebase] [--reference ] [--merge] [--recursive] [--] [...] or: $dashless [--quiet] summary [--cached|--files] [--summary-limit ] [commit] [--] [...] or: $dashless [--quiet] foreach [--recursive] or: $dashless [--quiet] sync [--] [...]" @@ -21,6 +21,7 @@ require_work_tree command= branch= force= +commit= reference= cached= recursive= @@ -239,6 +240,52 @@ module_clone() (clear_local_git_env; cd "$sm_path" && GIT_WORK_TREE=. git config core.worktree "$rel/$b") } +# +# Commit changed submodule gitlinks +# +# $1 = name-a;sha1-a;subsha1-a\n[name-b;sha1-b;subsha1-b\n...] +# +commit_changes() +{ + echo "commiting $1" + OIFS="$IFS" + IFS=";" + paths=$(echo "$1" | + while read name sm_path sha1 subsha1 + do + echo "$sm_path" + done + ) + names=$(echo "$1" | + while read name sm_path sha1 subsha1 + do + printf ' %s' "$name" + done + ) + summary="$(eval_gettext "Updated submodules:")$names" + body=$(echo "$1" | + while read name sm_path sha1 subsha1 + do + if test "$name" = "$sm_path" + then + printf 'Changes to %s:\n\n' "$name" + else + printf 'Changes to %s (%s):\n\n' "$name" "$sm_path" + fi + ( + clear_local_git_env + cd "$sm_path" && + git shortlog "${sha1}..${subsha1}" || + die "$(eval_gettext "Unable to generate shortlog in submodule path '\$sm_path'")" + ) + done + ) + IFS="$OIFS" + message="$(printf '%s\n\n%s\n' "$summary" "$body")" + echo "message: [$message]" + git commit -m "$message" $paths +} + # # Add a new submodule to the working tree, .gitmodules and the index # @@ -515,6 +562,9 @@ cmd_update() -f|--force) force=$1 ;; + --commit) + commit=1 + ;; -r|--rebase) update="rebase" ;; @@ -557,6 +607,7 @@ cmd_update() fi cloned_modules= + changed_modules= module_list "$@" | { err= while read mode sha1 stage sm_path @@ -660,6 +711,15 @@ Maybe you want to use 'update --init'?")" err="${err};$die_msg" continue fi + + subsha1=$(clear_local_git_env; cd "$sm_path" && + git rev-parse --verify HEAD) || + die "$(eval_gettext "Unable to find new revision in submodule path '\$sm_path'")" + + if test "$subsha1" != "$sha1" + then + changed_modules=$(printf '%s%s\n' "$changed_modules" "$name;$sm_path;$sha1;$subsha1") + fi fi if test -n "$recursive" @@ -680,6 +740,11 @@ Maybe you want to use 'update --init'?")" fi done + if test -z "$err" -a -n "$commit" -a -n "$changed_modules" + then + commit_changes "$changed_modules" + fi + if test -n "$err" then OIFS=$IFS @@ -1107,7 +1172,15 @@ do done # No command word defaults to "status" -test -n "$command" || command=status +if test -z "$command" +then + if test $# = 0 + then + command=status + else + usage + fi +fi # "-b branch" is accepted only by "add" if test -n "$branch" && test "$command" != add