Files
git.taskfile.build/bin/switch-git-folder
T
Janik von Rotz 30d8d7aa86 feat: standardize required/optional param notation and update error messages
- Updated `task`, `task.template`, and `library.md` to use angle brackets (`<param>`) for required parameters and square brackets (`[param]`) for optional ones.
- Fixed argument order mismatches in `create-symlink`, `create-symlink-files`, and `commit-git-folder` documentation.
- Removed non-existent `[path]` parameter from `merge-git-remote`.
- Standardized empty-argument error messages across `bin/*` scripts to use slash notation (e.g., `$1/path is empty.`).
- Updated prompt file `prompts/21_show-optional-and-required-params-in-task-help.md` to mark task as completed and log work.
2026-09-10 14:19:58 +02:00

41 lines
1.3 KiB
Bash
Executable File

#!/bin/bash
switch-git-folder() {
if [[ -z "$1" ]]; then
echo '$1/branch is empty.'
exit
fi
if [[ -z "$2" ]]; then
echo '$2/path is empty.'
exit
fi
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."
git -C "$git_folder" fetch origin "$git_branch:$git_branch"
git -C "$git_folder" switch "$git_branch"
else
echo "Switch git folder branch to $git_branch: $git_folder"
git -C "$git_folder" stash
git -C "$git_folder" switch "$git_branch"
fi
done
}
swgf() {
switch-git-folder "$@"
}