|
@@ -40,6 +40,14 @@ fn parse-git-branch {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+fn resolve-symbolic {|ref|
|
|
|
+ try {
|
|
|
+ put (git rev-parse --symbolic-full-name $ref 2> /dev/null)
|
|
|
+ } catch {
|
|
|
+ put $nil
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
fn parse-git-state {
|
|
|
var git-revision = ''
|
|
|
var git-branch = ''
|
|
@@ -47,15 +55,17 @@ fn parse-git-state {
|
|
|
var git-staged = (num 0)
|
|
|
var git-conflicts = (num 0)
|
|
|
var git-untracked = (num 0)
|
|
|
- var git-ahead = (num 0)
|
|
|
- var git-behind = (num 0)
|
|
|
+ var git-ahead-upstream = (num 0)
|
|
|
+ var git-behind-upstream = (num 0)
|
|
|
+ var git-ahead-push = (num 0)
|
|
|
+ var git-behind-push = (num 0)
|
|
|
|
|
|
git status --porcelain=v2 -b 2>/dev/null | each {|line|
|
|
|
if (eq '#' $line[0]) {
|
|
|
try {
|
|
|
var match = (re:find '# branch.ab \+(\d+) -(\d+)' $line)
|
|
|
- set git-ahead = (num $match[groups][1][text])
|
|
|
- set git-behind = (num $match[groups][2][text])
|
|
|
+ set git-ahead-upstream = (num $match[groups][1][text])
|
|
|
+ set git-behind-upstream = (num $match[groups][2][text])
|
|
|
} catch e {
|
|
|
# noop
|
|
|
}
|
|
@@ -93,16 +103,47 @@ fn parse-git-state {
|
|
|
set git-ref-prefix = '@'
|
|
|
set git-ref = $git-revision
|
|
|
}
|
|
|
+ } else {
|
|
|
+ var git-push = (resolve-symbolic '@{push}')
|
|
|
+ var git-upstream = (resolve-symbolic '@{upstream}')
|
|
|
+ var git-origin-head = (resolve-symbolic origin/HEAD)
|
|
|
+
|
|
|
+ if (not-eq $nil $git-push) {
|
|
|
+ if (eq $git-push $git-upstream) {
|
|
|
+ # if push is the same as upstream, use the values from git status
|
|
|
+ set git-behind-push = $git-behind-upstream
|
|
|
+ set git-ahead-push = $git-ahead-upstream
|
|
|
+ } else {
|
|
|
+ # else calculate it ourselves
|
|
|
+ var behind ahead = (str:split "\t" (git rev-list --count --left-right '@{push}...HEAD'))
|
|
|
+ set git-behind-push = (num $behind)
|
|
|
+ set git-ahead-push = (num $ahead)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ # if upstream is nil or the same as push, use origin/HEAD instead if
|
|
|
+ # present
|
|
|
+ if (and ^
|
|
|
+ (or (eq $git-push $git-upstream) (eq $nil $git-upstream)) ^
|
|
|
+ (not-eq $nil $git-origin-head) ^
|
|
|
+ ) {
|
|
|
+ var behind ahead = (str:split "\t" (git rev-list --count --left-right origin/HEAD...HEAD))
|
|
|
+ set git-behind-upstream = (num $behind)
|
|
|
+ set git-ahead-upstream = (num $ahead)
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
put '('
|
|
|
put $git-ref-prefix
|
|
|
styled $git-ref magenta bold
|
|
|
- if (> $git-ahead 0) {
|
|
|
- put '^'$git-ahead
|
|
|
+ if (> $git-ahead-push 0) {
|
|
|
+ put '^'$git-ahead-push
|
|
|
+ }
|
|
|
+ if (> $git-behind-push 0) {
|
|
|
+ put 'v'$git-behind-push
|
|
|
}
|
|
|
- if (> $git-behind 0) {
|
|
|
- put 'v'$git-behind
|
|
|
+ if (> $git-behind-upstream 0) {
|
|
|
+ put '!'
|
|
|
}
|
|
|
put '|'
|
|
|
if (> $git-staged 0) {
|