moved helpers separately

This commit is contained in:
2026-10-13 16:21:24 +02:00
parent ba1e07744e
commit 9911f6d01d
33 changed files with 1489 additions and 1089 deletions
+4 -97
View File
@@ -36,6 +36,10 @@
load_conf git
# Common helpers, then the ones private to this module (helpers/git.sh)
declare -F _profile_load_helpers >/dev/null || . "$(dirname -- "${BASH_SOURCE[0]}")/../helpers/common.sh"
_profile_load_helpers "${BASH_SOURCE[0]}"
# ------------------------------------------------------------------------------
# Built-in defaults (can be overridden from [git] section in profile.conf)
: "${GIT_MAIN_BRANCH:=main}"
@@ -43,81 +47,6 @@ load_conf git
: "${GIT_WIP_PREFIX:=wip}"
: "${GIT_GACP_AUTO_ADD:=1}"
# ------------------------------------------------------------------------------
# Internal helper: ensure git is available and cwd is a git worktree
_git_require_repo()
{
if ! command -v git >/dev/null 2>&1; then
disp E "git command not found."
return 1
fi
if ! git rev-parse --is-inside-work-tree >/dev/null 2>&1; then
disp E "Current directory is not inside a git repository."
return 1
fi
return 0
}
export -f _git_require_repo
# ------------------------------------------------------------------------------
# ------------------------------------------------------------------------------
# Internal helper: return default branch from remote HEAD, fallback to config
_git_default_branch()
{
local remote="${1:-$GIT_DEFAULT_REMOTE}"
local head
head=$(git symbolic-ref --quiet --short "refs/remotes/${remote}/HEAD" 2>/dev/null) || true
if [[ -n $head ]]; then
printf "%s\n" "${head#"${remote}"/}"
return 0
fi
printf "%s\n" "$GIT_MAIN_BRANCH"
return 0
}
export -f _git_default_branch
# ------------------------------------------------------------------------------
# ------------------------------------------------------------------------------
# Internal helper: print the name of the checked-out branch; fail with an error
# message on a detached HEAD (commands that push or rebase need a branch).
_git_current_branch()
{
local b
b=$(git symbolic-ref --quiet --short HEAD 2>/dev/null) || {
disp E "HEAD is detached: check out a branch first."
return 1
}
printf "%s\n" "$b"
}
export -f _git_current_branch
# ------------------------------------------------------------------------------
# ------------------------------------------------------------------------------
# Internal helper: print "<remote><TAB><branch>" for the remote branch tracked
# by local branch $1, read from its configuration (branch.<name>.remote/.merge).
# Unlike parsing the "origin/feature/x" form given by @{u}, this is exact for
# remote and branch names containing slashes. Fails when nothing is tracked or
# when the branch tracks another local branch (remote ".").
_git_tracking()
{
local branch=$1 remote merge
remote=$(git config --get "branch.${branch}.remote") || return 1
merge=$(git config --get "branch.${branch}.merge") || return 1
[[ $remote == "." ]] && return 1
printf "%s\t%s\n" "$remote" "${merge#refs/heads/}"
}
export -f _git_tracking
# ------------------------------------------------------------------------------
# ------------------------------------------------------------------------------
# Display compact git status + branch tracking information
# Usage: gst [path]
@@ -165,9 +94,6 @@ gst()
git -C "$target" status --short --branch
}
export -f gst
# ------------------------------------------------------------------------------
# ------------------------------------------------------------------------------
# Show a readable commit graph
# Usage: ggraph [-n limit]
@@ -219,9 +145,6 @@ ggraph()
git log --graph --decorate --oneline --all --max-count="$limit"
}
export -f ggraph
# ------------------------------------------------------------------------------
# ------------------------------------------------------------------------------
# Sync current branch with remote (fetch + rebase)
# Usage: gsync [remote]
@@ -288,9 +211,6 @@ gsync()
git rebase "$upstream"
}
export -f gsync
# ------------------------------------------------------------------------------
# ------------------------------------------------------------------------------
# Add, commit, and push changes with automatic pull/rebase if needed
# Usage: gacp -m "message" [file1 file2 ...]
@@ -414,9 +334,6 @@ gacp()
return 0
}
export -f gacp
# ------------------------------------------------------------------------------
# ------------------------------------------------------------------------------
# Reset local branch to exact upstream state (stash local changes first)
# Usage: greset [target]
@@ -553,9 +470,6 @@ greset()
return 0
}
export -f greset
# ------------------------------------------------------------------------------
# ------------------------------------------------------------------------------
# Create a quick WIP commit for local checkpointing
# Usage: gwip [message]
@@ -604,9 +518,6 @@ gwip()
git commit -m "$msg"
}
export -f gwip
# ------------------------------------------------------------------------------
# ------------------------------------------------------------------------------
# Delete merged local branches (except protected branches)
# Usage: gprune [-D|--deep] [main-branch]
@@ -728,9 +639,6 @@ gprune()
fi
}
export -f gprune
# ------------------------------------------------------------------------------
# ------------------------------------------------------------------------------
# Print repository root path
# Usage: groot
@@ -790,5 +698,4 @@ groot()
export -f groot
# ------------------------------------------------------------------------------
# EOF