diff options
author | Michael Allen <michael@michaelallen.io> | 2015-02-12 16:53:08 +0000 |
---|---|---|
committer | Michael Allen <michael@michaelallen.io> | 2015-02-12 16:53:08 +0000 |
commit | 43ac2a587f9b0b218875e3f1aa5a68ed4f1f8f19 (patch) | |
tree | a7557b5d64beab088a919562a359e72d925c3726 /git-base.sh | |
parent | 8d7c08e7f0d1fd880345cf4c62b0568e509ce13a (diff) | |
download | git-sonar-43ac2a587f9b0b218875e3f1aa5a68ed4f1f8f19.tar.gz git-sonar-43ac2a587f9b0b218875e3f1aa5a68ed4f1f8f19.zip |
find branch names and commits ahead or behind
Diffstat (limited to 'git-base.sh')
-rwxr-xr-x | git-base.sh | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/git-base.sh b/git-base.sh index 39e7367..9ffda78 100755 --- a/git-base.sh +++ b/git-base.sh @@ -1,5 +1,6 @@ dot_git="" cwd="" +remote="" in_current_dir() { local wd="$(pwd)" @@ -96,3 +97,56 @@ fetch() { git fetch debug_print $debug "Finished fetch" } + +branch_name() { + if is_repo; then + local localBranch="$(git symbolic-ref --short HEAD)" + echo $localBranch + fi +} + +is_tracking_remote() { + if [[ -n "$(remote_branch_name)" ]]; then + return 0 + else + return 1 + fi +} + +remote_branch_name() { + if is_repo; then + local remoteBranch="$(git for-each-ref --format='%(upstream:short)' | grep "$(branch_name)")" + if [[ -n $remoteBranch ]]; then + echo $remoteBranch + return 0 + else + return 1 + fi + fi +} + +commits_behind_of_remote() { + if is_tracking_remote; then + set -- + set -- $(git rev-list --left-right --count $(remote_branch_name)...HEAD) + behind=$1 + ahead=$2 + set -- + echo $behind + else + echo "0" + fi +} + +commits_ahead_of_remote() { + if is_tracking_remote; then + set -- + set -- $(git rev-list --left-right --count $(remote_branch_name)...HEAD) + behind=$1 + ahead=$2 + set -- + echo $ahead + else + echo "0" + fi +} |