feature (git): add plugin functions for default branch and delete stale branch

pull/2112/head
Gurkirat Singh 2022-03-07 11:29:29 +05:30
parent 3a778072db
commit d059308c97
No known key found for this signature in database
GPG Key ID: 5D829219EF259AA5
1 changed files with 59 additions and 35 deletions

View File

@ -3,7 +3,7 @@ cite about-plugin
about-plugin 'git helper functions'
# shellcheck disable=SC2016
function git_remote {
function git_remote() {
about 'adds remote $GIT_HOSTING:$1 to current repo'
group "git"
@ -11,7 +11,7 @@ function git_remote {
git remote add origin "${GIT_HOSTING}:${1}".git
}
function git_first_push {
function git_first_push() {
about 'push into origin refs/heads/master'
group 'git'
@ -158,7 +158,7 @@ function git_info() {
fi
}
function git_stats {
function git_stats() {
about 'display stats per author'
group 'git'
@ -314,3 +314,27 @@ function git-changelog() {
done
fi
}
function git-get-default-branch() {
about 'gets the default branch of the git repo'
group 'git'
example '$ git-get-default-branch'
echo $(basename $(git symbolic-ref refs/remotes/origin/HEAD))
}
function git-delete-stale-branch() {
about 'deletes the stale branch from git'
group 'git'
example '$ git-delete-stale-branch [--force|-f]'
local CURR_BRANCH
CURR_BRANCH=$(git branch | grep "*" | awk '{print $2}')
if [[ "$1" == "--force" ]] || [[ "$1" == "-f" ]]; then
git branch | grep -vE "$(git-get-default-branch)|$CURR_BRANCH" | xargs git branch -D
else
git branch | grep -vE "$(git-get-default-branch)|$CURR_BRANCH" | xargs git branch -d
fi
}