feat(git): add comprehensive git folder management commands and update documentation
This commit is contained in:
15 files changed
+342
-10
No files matched your search
Executable
+31
@@ -0,0 +1,31 @@
|
||||
#!/bin/bash
|
||||
|
||||
switch-git-folder() {
|
||||
if [[ -z "$1" ]]; then
|
||||
echo '$1/path 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)
|
||||
|
||||
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
|
||||
}
|
||||
Reference in new issue
Block a user