From 0c0231a2ef26cd3497d123df69a73baf533586c7 Mon Sep 17 00:00:00 2001 From: Julian Prein Date: Tue, 28 Jan 2025 17:25:29 +0100 Subject: [PATCH] git:ssync: Add --new flag I sometimes do not want to change the working tree of submodules I changed locally. --- .config/zsh/autoload/git/git-ssync | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/.config/zsh/autoload/git/git-ssync b/.config/zsh/autoload/git/git-ssync index 9d290c0..3a0d4e4 100755 --- a/.config/zsh/autoload/git/git-ssync +++ b/.config/zsh/autoload/git/git-ssync @@ -3,4 +3,24 @@ emulate -L zsh -o err_return git submodule sync --recursive -git submodule update --init --recursive + +if [[ "$1" == "--new" ]]; then + # Only checkout new submodules + + local toplevel + toplevel="$(git rev-parse --show-toplevel)" + cd "$toplevel" + + grep path .gitmodules \ + | cut -d= -f2 \ + | sed 's/^\s*//' \ + | while read -r line; do + # keep only empty ones + find "$line" -maxdepth 0 -empty + done \ + | while read -r line; do + git submodule update --init --recursive -- "$line" + done +else + git submodule update --init --recursive +fi