Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add base group scripts. #7

Merged
merged 8 commits into from
Nov 13, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions .tools/git_group_functions.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Function to check if a directory is a Git repository
is_git_repo() {
git -C "$1" rev-parse --is-inside-work-tree &>/dev/null
}

recursive_git() {
repo_dirs=($(find "$(pwd)" -type d -name ".git" -exec dirname {} \;))
repo_dirs=($(for i in "${repo_dirs[@]}"; do echo "$i"; done | sort))

for repo_dir in "${repo_dirs[@]}"; do
if is_git_repo "$repo_dir"; then
relative_repo_dir=$(realpath --relative-to="$(pwd)" "$repo_dir")
echo "git -C $relative_repo_dir ${@:1}"
git -C "$relative_repo_dir" ${@:1}
fi
done
}

# Not sure how to share the common code between these two
recursive_git_delete_merged_branches() {
repo_dirs=($(find "$(pwd)" -type d -name ".git" -exec dirname {} \;))
repo_dirs=($(for i in "${repo_dirs[@]}"; do echo "$i"; done | sort))

for repo_dir in "${repo_dirs[@]}"; do
if is_git_repo "$repo_dir"; then
relative_repo_dir=$(realpath --relative-to="$(pwd)" "$repo_dir")
echo "git -C $relative_repo_dir for-each-ref --format '%(refname:short) %(upstream:track)' | awk '\$2 == "[gone]" {print \$1}' | xargs -r git -C $repo_dir branch -D"
git -C "$relative_repo_dir" for-each-ref --format '%(refname:short) %(upstream:track)' | awk '$2 == "[gone]" {print $1}' | xargs -r git -C $repo_dir branch -D
fi
done
}

4 changes: 4 additions & 0 deletions .tools/recursive_git.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/bash

source "$(dirname "$0")/git_group_functions.sh"
recursive_git "$@"
4 changes: 4 additions & 0 deletions .tools/recursive_git_delete_merged_branches.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/bash

source "$(dirname "$0")/git_group_functions.sh"
recursive_git_delete_merged_branches
17 changes: 17 additions & 0 deletions .tools/recursive_git_reset_branch.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/bin/bash

source "$(dirname "$0")/git_group_functions.sh"

recursive_git fetch --all --prune
recursive_git checkout develop
recursive_git reset --hard
recursive_git pull

recursive_git_delete_merged_branches

if [ "$1" != "develop" ]; then
recursive_git checkout $1
recursive_git reset --hard
recursive_git pull
recursive_git rebase develop
fi