forked from darkwater/dotfiles
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path.githelpers
More file actions
61 lines (50 loc) · 1.61 KB
/
.githelpers
File metadata and controls
61 lines (50 loc) · 1.61 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
#!/bin/bash
FORMAT="%C(bold cyan)%h%C(reset) %C(blue)%ar%C(reset) %C(bold red)% D%C(reset)%n %C(white)%w($(($(tput cols) - 20)),0,2)%s%C(reset)%w() %C(yellow)- %an%C(reset)%n"
show_git_head()
{
pretty_git_log -1
git show -p --pretty="tformat:"
}
pretty_git_log()
{
git log --color=always --graph --pretty="tformat:${FORMAT}" $* |
sed -Ee 's/\|/│/g' \
-e 's/\/(\x1b\[m)/╱\1/g' \
-e 's/\\(\x1b\[m)/╲\1/g' |
# Page only if we're asked to.
if [ -n "$GIT_NO_PAGER" ]; then
cat
else
# Page only if needed.
less --quit-if-one-screen --no-init --RAW-CONTROL-CHARS --chop-long-lines
fi
}
push_wip()
{
branch="$(git rev-parse --abbrev-ref HEAD)"
remote="$(git config "branch.$branch.remote")"
identifier="$1"
tag="wip-${identifier:-$(whoami)}"
git stash -a
git push "$remote" "+refs/stash:refs/tags/$tag"
}
pull_wip()
{
branch="$(git rev-parse --abbrev-ref HEAD)"
remote="$(git config "branch.$branch.remote")"
identifier="$1"
tag="wip-${identifier:-$(whoami)}"
ref="refs/tags/$tag"
object="$(git ls-remote "$remote" "$ref" | awk '{ print $1 }')"
git="$(git rev-parse --show-cdup).git"
# Download wip object
git fetch "$remote" "$ref"
# Tell Git this is a stash thing
echo "$object" > "$git/refs/stash"
git log "$object" -1 --format="0000000000000000000000000000000000000000 %H %an <%ae> %ad %s" \
--date=format:"%s %z" > "$git/logs/refs/stash"
# Pop it
git stash pop
# Delete remote wip object
git push "$remote" ":$ref"
}