git stash: avoid data loss when "git stash save" kills a directory
[gitweb.git] / git-submodule.sh
index 275c664ff55f2d669ad302f0b11d8629b2d7d1ec..eb58c8e89d28626fed56604533ffb4b87991a6af 100755 (executable)
@@ -113,7 +113,7 @@ resolve_relative_url ()
 module_list()
 {
        (
-               git ls-files --error-unmatch --stage -- "$@" ||
+               git ls-files -z --error-unmatch --stage -- "$@" ||
                echo "unmatched pathspec exists"
        ) |
        perl -e '
@@ -121,6 +121,7 @@ module_list()
        my ($null_sha1) = ("0" x 40);
        my @out = ();
        my $unmatched = 0;
+       $/ = "\0";
        while (<STDIN>) {
                if (/^unmatched pathspec/) {
                        $unmatched = 1;
@@ -606,10 +607,12 @@ cmd_deinit()
 
                        if test -z "$force"
                        then
-                               git rm -n "$sm_path" ||
+                               git rm -qn "$sm_path" ||
                                die "$(eval_gettext "Submodule work tree '\$sm_path' contains local modifications; use '-f' to discard them")"
                        fi
-                       rm -rf "$sm_path" || say "$(eval_gettext "Could not remove submodule work tree '\$sm_path'")"
+                       rm -rf "$sm_path" &&
+                       say "$(eval_gettext "Cleared directory '\$sm_path'")" ||
+                       say "$(eval_gettext "Could not remove submodule work tree '\$sm_path'")"
                fi
 
                mkdir "$sm_path" || say "$(eval_gettext "Could not create empty submodule directory '\$sm_path'")"
@@ -1127,16 +1130,16 @@ cmd_status()
                        say "-$sha1 $displaypath"
                        continue;
                fi
-               set_name_rev "$sm_path" "$sha1"
                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=$(clear_local_git_env; cd "$sm_path" && git rev-parse --verify HEAD)
-                               set_name_rev "$sm_path" "$sha1"
                        fi
+                       set_name_rev "$sm_path" "$sha1"
                        say "+$sha1 $displaypath$revname"
                fi