Repository navigation
Expand file tree
/
Copy pathgit-fflocals
More file actions
executable file
·62 lines (53 loc) · 1.85 KB
/
Copy pathgit-fflocals
File metadata and controls
executable file
·62 lines (53 loc) · 1.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#!/usr/bin/env zsh
if [[ $1 == --fetch ]]; then
git fetch --all
fi
# Associative array of branches and upstreams. The keys are the local branches
# and the values are their upstreams (if any)
declare -A upstreams
eval "upstreams=($(git for-each-ref --shell --format='%(refname) %(upstream)' 'refs/heads/*'))"
# Fast-forward the current branch (if any; current is HEAD otherwise) and
# delete it from upstreams
current=$(git rev-parse --symbolic-full-name HEAD)
if [[ $current != HEAD ]] && (( ${upstreams[$current]:+1} )); then
# TODO: Filter out in for-each-ref above to avoid this condition
if git rev-parse --quiet --verify "$upstreams[$k]" >/dev/null; then
if ! git merge --ff-only '@{u}' | awk 'NR == 1 && $0 == "Already up to date." { exit 1 } 1 { print }'; then
uptodate=${current#refs/heads/}
else
echo
fi
fi
unset "upstreams[$current]"
fi
# Iterate through the keys of the non-empty values
for k in ${(k)upstreams[(R)*?]}; do
# TODO: Filter out in for-each-ref above to avoid this condition
if git rev-parse --quiet --verify "$upstreams[$k]" >/dev/null; then
refspecs+=($upstreams[$k]:$k)
fi
done
git -c advice.pushNonFFMatching=false push --porcelain --no-atomic . $refspecs 2>&1 | awk -v uptodate=$uptodate -F '[:\t]' '
# Get rid of prefix
1 { sub("^refs/heads/", "", $3) }
# Successful Fast-forward
$1 == " " { updated[$3] = $4 }
# Up to date
$1 == "=" { uptodate = uptodate ", " $3 }
# Failed
$1 == "!" { reasons[$4] = reasons[$4] ", " $3 }
END {
for (i in updated) {
print "Updated:", i
system("git --no-pager diff --stat " updated[i])
}
if (length(uptodate) > 0) {
sub("^, ", "", uptodate)
print "Up to date:", uptodate
}
for (i in reasons) {
sub("^, ", "", reasons[i])
print "Failed: " i ": " reasons[i]
}
}
'