mermaid save to file, fix
This commit is contained in:
@ -1,11 +1,15 @@
|
|||||||
$ #!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
# Function to escape special characters for Mermaid
|
# Function to escape special characters for Mermaid
|
||||||
escape_for_mermaid() {
|
escape_for_mermaid() {
|
||||||
echo "$1" | sed 's/[^a-zA-Z0-9]/_/g'
|
echo "$1" | sed 's/[^a-zA-Z0-9]/_/g'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Output file
|
||||||
|
output_file="branches_diagram.mmd"
|
||||||
|
|
||||||
# Start the Mermaid diagram
|
# Start the Mermaid diagram
|
||||||
|
{
|
||||||
echo "%%{init: { 'theme': 'base' } }%%"
|
echo "%%{init: { 'theme': 'base' } }%%"
|
||||||
echo "gitGraph"
|
echo "gitGraph"
|
||||||
|
|
||||||
@ -14,9 +18,12 @@ main_branch="master"
|
|||||||
|
|
||||||
# Start with the main branch
|
# Start with the main branch
|
||||||
echo " commit id: \"Initial commit\""
|
echo " commit id: \"Initial commit\""
|
||||||
|
echo " branch $main_branch"
|
||||||
|
echo " checkout $main_branch"
|
||||||
|
|
||||||
# Keep track of declared branches
|
# Keep track of declared branches
|
||||||
declared_branches=("$main_branch")
|
declare -A declared_branches
|
||||||
|
declared_branches[$main_branch]=1
|
||||||
|
|
||||||
# Function to find the base branch
|
# Function to find the base branch
|
||||||
find_base_branch() {
|
find_base_branch() {
|
||||||
@ -32,6 +39,26 @@ find_base_branch() {
|
|||||||
# Function to declare a branch if not already declared
|
# Function to declare a branch if not already declared
|
||||||
declare_branch() {
|
declare_branch() {
|
||||||
local branch=$1
|
local branch=$1
|
||||||
if [[ ! " ${declared_branches[@]} " =~ " ${branch} " ]]; then
|
if [[ -z "${declared_branches[$branch]}" ]]; then
|
||||||
echo " branch $branch"
|
echo " branch $(escape_for_mermaid "$branch")"
|
||||||
doneprocess_branch "$branch"--sort=committerdate --format='%(refname:short)' refs/heads/)
|
declared_branches[$branch]=1
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
# Process each branch
|
||||||
|
for branch in $(git for-each-ref --sort=committerdate --format='%(refname:short)' refs/heads/); do
|
||||||
|
base_branch=$(find_base_branch "$branch")
|
||||||
|
|
||||||
|
declare_branch "$branch"
|
||||||
|
|
||||||
|
echo " checkout $(escape_for_mermaid "$branch")"
|
||||||
|
echo " commit id: \"$(git log -1 --pretty=format:%s "$branch")\""
|
||||||
|
|
||||||
|
if [ "$branch" != "$main_branch" ]; then
|
||||||
|
echo " checkout $(escape_for_mermaid "$base_branch")"
|
||||||
|
echo " merge $(escape_for_mermaid "$branch")"
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
} > $output_file
|
||||||
|
|
||||||
|
echo "Mermaid diagram saved to $output_file"
|
||||||
|
Reference in New Issue
Block a user