From 1ea2f19d1197d2f5aa600da93c8286cd8066df7f Mon Sep 17 00:00:00 2001 From: Dobromir Popov Date: Tue, 16 Jul 2024 12:05:04 +0300 Subject: [PATCH] generate marmaid graph --- git/generae_overview_mermaid.sh | 37 +++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 git/generae_overview_mermaid.sh diff --git a/git/generae_overview_mermaid.sh b/git/generae_overview_mermaid.sh new file mode 100644 index 0000000..103f7c3 --- /dev/null +++ b/git/generae_overview_mermaid.sh @@ -0,0 +1,37 @@ +$ #!/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/) \ No newline at end of file