diff --git a/bin/clone-git-folder b/bin/clone-git-folder index ead5a2e..b9dd71d 100755 --- a/bin/clone-git-folder +++ b/bin/clone-git-folder @@ -8,7 +8,6 @@ clone-git-folder() { local git_folders=$(ls-git-folder "$1") for git_folder in $git_folders; do - git_folder="${git_folder#./}" local git_folder_path=$(git config --file .gitmodules --get submodule."$git_folder".path) @@ -16,6 +15,17 @@ clone-git-folder() { local shallow=$(git config --file .gitmodules --get submodule."$git_folder".shallow) local git_folder_branch=$(git config --file .gitmodules --get submodule."$git_folder".branch) + if [[ -z "$git_folder_path" ]] || [[ -z "$git_folder_url" ]]; then + echo "Skipping: '$git_folder' not defined in .gitmodules." + continue + fi + + # Skip if directory exists and is not empty + if [[ -d "$git_folder_path" ]] && [[ -n "$(ls -A "$git_folder_path")" ]]; then + echo "Skipping: '$git_folder_path' already exists and is not empty." + continue + fi + if [[ "$shallow" = "true" ]]; then echo "Clone git folder $git_folder (shallow) with $git_folder_branch branch" git -C "$git_folder" config remote.origin.fetch "+refs/heads/*:refs/remotes/origin/*" diff --git a/bin/pull-git-folder b/bin/pull-git-folder index 0f93b6d..abb30bf 100755 --- a/bin/pull-git-folder +++ b/bin/pull-git-folder @@ -12,11 +12,18 @@ pull-git-folder() { local git_folders=$(ls-git-folder "$2") for git_folder in $git_folders; do + git_folder="${git_folder#./}" + + local git_folder_path=$(git config --file .gitmodules --get submodule."$git_folder".path) + local git_folder_url=$(git config --file .gitmodules --get submodule."$git_folder".url) + + if [[ -z "$git_folder_path" ]] || [[ -z "$git_folder_url" ]]; then + echo "Skipping: '$git_folder' not defined in .gitmodules." + continue + fi + echo "Pull git folder $git_folder." git -C "$git_folder" stash - local update=$(git config submodule."$git_folder".update) - if [[ -z "$update" ]]; then - git -C "$git_folder" pull origin "$1" - fi; + git -C "$git_folder" pull origin "$1" done } \ No newline at end of file diff --git a/bin/switch-git-folder b/bin/switch-git-folder index 2ee2881..a0d5d0f 100755 --- a/bin/switch-git-folder +++ b/bin/switch-git-folder @@ -13,10 +13,16 @@ switch-git-folder() { local git_branch="$1" local git_folders=$(ls-git-folder "$2") for git_folder in $git_folders; do - git_folder="${git_folder#./}" local shallow=$(git config --file .gitmodules --get submodule."$git_folder".shallow) + local git_folder_path=$(git config --file .gitmodules --get submodule."$git_folder".path) + local git_folder_url=$(git config --file .gitmodules --get submodule."$git_folder".url) + + if [[ -z "$git_folder_path" ]] || [[ -z "$git_folder_url" ]]; then + echo "Skipping: '$git_folder' not defined in .gitmodules." + continue + fi if [[ "$shallow" = "true" ]]; then echo "Fetch branch $git_branch (shallow) from origin and then switch." diff --git a/bin/sync-git-folder b/bin/sync-git-folder index 3760f93..7e83c4c 100755 --- a/bin/sync-git-folder +++ b/bin/sync-git-folder @@ -11,6 +11,6 @@ sync-git-folder() { fi echo 'Switch and pull git folders.' - switch-git-folder "$" - pull-git-folder "$1" "$1" + switch-git-folder "$1" "$2" + pull-git-folder "$1" "$2" } \ No newline at end of file