-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgit-uncommit
More file actions
executable file
·93 lines (67 loc) · 2.11 KB
/
git-uncommit
File metadata and controls
executable file
·93 lines (67 loc) · 2.11 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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#!/bin/sh
# Copyright (c) 2013, 2014 Michele Bini
# This program is free software: you can redistribute it and/or modify
# it under the terms of the version 3 of the GNU General Public License
# as published by the Free Software Foundation.
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
set -e
println() {
printf "%s\n" "$*"
}
warn() {
println "$0: $*" >&2
}
die() {
warn "$*"
exit 1
}
toascii() {
if which uni2ascii >/dev/null 2>&1; then
uni2ascii -qBP
else
cat
fi
}
namecommit() {
(git show "$1"|git patch-id|head --bytes=7; git show "$1"|head -n5|tail -n1)|toascii|sed -E "; s/[^a-zA-Z0-9]+/ /g; s/^ //; s/ $//; s/ /-/g"|head --bytes=40|tr A-Z a-z|sed "s/-$//"
}
branchname() {
git branch|sed -n "s/[*] //p"
}
selectbranch() {
git symbolic-ref HEAD refs/heads/"$1"
}
noerr() {
"$@" 2>/dev/null
}
# Top level of the work tree, if possible relative to current directory
topleveldir="$(noerr git rev-parse --show-cdup || noerr git rev-parse --show-toplevel)"
# Current directory, relative to top level of work tree
prefixdir="$(noerr git rev-parse --show-prefix)"
withfinalslash() {
if [ -z "$1" ]; then return; fi
case "$1" in
*/) println "$1" ;;
*) println "$1"/ ;;
esac
}
topleveldir="$(withfinalslash "$topleveldir")"
prefixdir="$(withfinalslash "$prefixdir")"
f="$(namecommit HEAD)"
[ -z "f" ] && die "Internal error: Could not create patch name"
f="$f".patch
# gitdir="$(git rev-parse --git-dir)"
# t="$(git rev-parse --show-toplevel)"
# cd "$t"
git format-patch --binary -M70% -C70% -N -1 --stdout >"$f"
b="$(branchname)"
f="$prefixdir$f"
git checkout --quiet --detach HEAD^
println "Uncommit: $f"
println "Uncommit: $f" >>"$topleveldir".uncommitted-patches
[ -n "$b" ] && selectbranch "$b" && git reset --soft HEAD^