37 lines
1012 B
Bash
37 lines
1012 B
Bash
$ #!/bin/bash
|
|
|
|
# Function to escape special characters for Mermaid
|
|
escape_for_mermaid() {
|
|
echo "$1" | sed 's/[^a-zA-Z0-9]/_/g'
|
|
}
|
|
|
|
# Start the Mermaid diagram
|
|
echo "%%{init: { 'theme': 'base' } }%%"
|
|
echo "gitGraph"
|
|
|
|
# Set master as the main branch
|
|
main_branch="master"
|
|
|
|
# Start with the main branch
|
|
echo " commit id: \"Initial commit\""
|
|
|
|
# Keep track of declared branches
|
|
declared_branches=("$main_branch")
|
|
|
|
# Function to find the base branch
|
|
find_base_branch() {
|
|
local branch=$1
|
|
local base=$(git show-branch -a 2>/dev/null | grep '\*' | grep -v "$branch" | head -n1 | sed 's/.*\[\(.*\)\].*/\1/' | sed 's/[\^~].*//')
|
|
if [[ -z "$base" ]]; then
|
|
echo "$main_branch"
|
|
else
|
|
echo "$base"
|
|
fi
|
|
}
|
|
|
|
# Function to declare a branch if not already declared
|
|
declare_branch() {
|
|
local branch=$1
|
|
if [[ ! " ${declared_branches[@]} " =~ " ${branch} " ]]; then
|
|
echo " branch $branch"
|
|
doneprocess_branch "$branch"--sort=committerdate --format='%(refname:short)' refs/heads/) |