diff mbox series

[03/10] git-submodule: allow partial update of .git-submodule-status

Message ID 20230605095223.107653-4-pbonzini@redhat.com
State New
Headers show
Series meson: replace submodules with wrap files | expand

Commit Message

Paolo Bonzini June 5, 2023, 9:52 a.m. UTC
Allow a specific subdirectory to run git-submodule.sh with only a
subset of submodules, without removing the others from the
.git-submodule-status file.

This also allows scripts/git-submodule.sh to be more lenient:
validating an empty set of submodules is not a mistake.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 scripts/git-submodule.sh | 26 ++++++++++++++------------
 1 file changed, 14 insertions(+), 12 deletions(-)

Comments

Alex Bennée June 5, 2023, 10:55 a.m. UTC | #1
Paolo Bonzini <pbonzini@redhat.com> writes:

> Allow a specific subdirectory to run git-submodule.sh with only a
> subset of submodules, without removing the others from the
> .git-submodule-status file.
>
> This also allows scripts/git-submodule.sh to be more lenient:
> validating an empty set of submodules is not a mistake.
>
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>

Reviewed-by: Alex Bennée <alex.bennee@linaro.org>
diff mbox series

Patch

diff --git a/scripts/git-submodule.sh b/scripts/git-submodule.sh
index 0ce1efc44e5..b7d8f05352c 100755
--- a/scripts/git-submodule.sh
+++ b/scripts/git-submodule.sh
@@ -72,12 +72,8 @@  done
 
 case "$command" in
 status|validate)
-    if test -z "$maybe_modules"
-    then
-         test -s ${substat} && validate_error "$command" || exit 0
-    fi
-
     test -f "$substat" || validate_error "$command"
+    test -z "$maybe_modules" && exit 0
     for module in $modules; do
         CURSTATUS=$($GIT submodule status $module)
         OLDSTATUS=$(cat $substat | grep $module)
@@ -88,17 +84,23 @@  status|validate)
     exit 0
     ;;
 update)
-    if test -z "$maybe_modules"
-    then
-        test -e $substat || touch $substat
-        exit 0
-    fi
+    test -e $substat || touch $substat
+    test -z "$maybe_modules" && exit 0
 
     $GIT submodule update --init $modules 1>/dev/null
     test $? -ne 0 && update_error "failed to update modules"
 
-    $GIT submodule status $modules > "${substat}"
-    test $? -ne 0 && update_error "failed to save git submodule status" >&2
+    (while read -r; do
+        for module in $modules; do
+            case $REPLY in
+                *" $module "*) continue 2 ;;
+            esac
+        done
+        printf '%s\n' "$REPLY"
+    done
+    $GIT submodule status $modules
+    test $? -ne 0 && update_error "failed to save git submodule status" >&2) < $substat > $substat.new
+    mv -f $substat.new $substat
     ;;
 esac