]> rtime.felk.cvut.cz Git - git.git/blobdiff - git-submodule.sh
Update draft release notes to 1.7.2
[git.git] / git-submodule.sh
index 77d223292c5b167a8a33b04b10b46426b68e0576..8c562a72e6e95fce60b78c015623212b7fce1dab 100755 (executable)
@@ -21,6 +21,8 @@ command=
 branch=
 reference=
 cached=
+recursive=
+init=
 files=
 nofetch=
 update=
@@ -222,7 +224,7 @@ cmd_add()
 
                module_clone "$path" "$realrepo" "$reference" || exit
                (
-                       unset GIT_DIR
+                       clear_local_git_env
                        cd "$path" &&
                        # ash fails to wordsplit ${branch:+-b "$branch"...}
                        case "$branch" in
@@ -269,6 +271,8 @@ cmd_foreach()
                shift
        done
 
+       toplevel=$(pwd)
+
        module_list |
        while read mode sha1 stage path
        do
@@ -278,7 +282,7 @@ cmd_foreach()
                        name=$(module_name "$path")
                        (
                                prefix="$prefix$path/"
-                               unset GIT_DIR
+                               clear_local_git_env
                                cd "$path" &&
                                eval "$@" &&
                                if test -n "$recursive"
@@ -434,7 +438,7 @@ cmd_update()
                        module_clone "$path" "$url" "$reference"|| exit
                        subsha1=
                else
-                       subsha1=$(unset GIT_DIR; cd "$path" &&
+                       subsha1=$(clear_local_git_env; cd "$path" &&
                                git rev-parse --verify HEAD) ||
                        die "Unable to find current revision in submodule path '$path'"
                fi
@@ -454,7 +458,7 @@ cmd_update()
 
                        if test -z "$nofetch"
                        then
-                               (unset GIT_DIR; cd "$path" &&
+                               (clear_local_git_env; cd "$path" &&
                                        git-fetch) ||
                                die "Unable to fetch in submodule path '$path'"
                        fi
@@ -477,14 +481,14 @@ cmd_update()
                                ;;
                        esac
 
-                       (unset GIT_DIR; cd "$path" && $command "$sha1") ||
+                       (clear_local_git_env; cd "$path" && $command "$sha1") ||
                        die "Unable to $action '$sha1' in submodule path '$path'"
                        say "Submodule path '$path': $msg '$sha1'"
                fi
 
                if test -n "$recursive"
                then
-                       (unset GIT_DIR; cd "$path" && cmd_update $orig_args) ||
+                       (clear_local_git_env; cd "$path" && cmd_update $orig_args) ||
                        die "Failed to recurse into submodule path '$path'"
                fi
        done
@@ -492,7 +496,7 @@ cmd_update()
 
 set_name_rev () {
        revname=$( (
-               unset GIT_DIR
+               clear_local_git_env
                cd "$1" && {
                        git describe "$2" 2>/dev/null ||
                        git describe --tags "$2" 2>/dev/null ||
@@ -553,12 +557,17 @@ cmd_summary() {
 
        test $summary_limit = 0 && return
 
-       if rev=$(git rev-parse -q --verify "$1^0")
+       if rev=$(git rev-parse -q --verify --default HEAD ${1+"$1"})
        then
                head=$rev
-               shift
+               test $# = 0 || shift
+       elif test -z "$1" -o "$1" = "HEAD"
+       then
+               # before the first commit: compare with an empty tree
+               head=$(git hash-object -w -t tree --stdin </dev/null)
+               test -z "$1" || shift
        else
-               head=HEAD
+               head="HEAD"
        fi
 
        if [ -n "$files" ]
@@ -643,7 +652,7 @@ cmd_summary() {
                                range=$sha1_dst
                        fi
                        GIT_DIR="$name/.git" \
-                       git log --pretty=oneline --first-parent $range | wc -l
+                       git rev-list --first-parent $range -- | wc -l
                        )
                        total_commits=" ($(($total_commits + 0)))"
                        ;;
@@ -688,7 +697,11 @@ cmd_summary() {
                echo
        done |
        if test -n "$for_status"; then
-               echo "# Modified submodules:"
+               if [ -n "$files" ]; then
+                       echo "# Submodules changed but not updated:"
+               else
+                       echo "# Submodule changes to be committed:"
+               fi
                echo "#"
                sed -e 's|^|# |' -e 's|^# $|#|'
        else
@@ -753,7 +766,7 @@ cmd_status()
                else
                        if test -z "$cached"
                        then
-                               sha1=$(unset GIT_DIR; cd "$path" && git rev-parse --verify HEAD)
+                               sha1=$(clear_local_git_env; cd "$path" && git rev-parse --verify HEAD)
                                set_name_rev "$path" "$sha1"
                        fi
                        say "+$sha1 $displaypath$revname"
@@ -763,7 +776,7 @@ cmd_status()
                then
                        (
                                prefix="$displaypath/"
-                               unset GIT_DIR
+                               clear_local_git_env
                                cd "$path" &&
                                cmd_status $orig_args
                        ) ||
@@ -814,7 +827,7 @@ cmd_sync()
                if test -e "$path"/.git
                then
                (
-                       unset GIT_DIR
+                       clear_local_git_env
                        cd "$path"
                        remote=$(get_default_remote)
                        say "Synchronizing submodule url for '$name'"