-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgit-fixup
More file actions
executable file
·39 lines (33 loc) · 949 Bytes
/
git-fixup
File metadata and controls
executable file
·39 lines (33 loc) · 949 Bytes
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
#!/bin/zsh
# git rev-list 'HEAD^..HEAD'
if (( ! $+commands[git-deps] )); then
echo 'Required dependency git-deps was not found in path.' >&2
exit
fi
if git diff --cached --quiet; then
echo 'No staged changes.' >&2
exit
fi
git commit -m 'git-fixup temporary commit' --quiet
if (( $? )); then
echo 'Failed committing index.' >&2
fi
typeset -a deps
deps=( ${(f)"$(git deps -e master HEAD)"} )
if (( $#deps == 1 )); then
echo "Index depends on one commit only:"
git log -n 1 --oneline $deps[1]
echo "Creating fixup commit:"
git commit --amend --fixup=$deps[1] --quiet
git log -n 1 --oneline HEAD
elif (( $#deps == 0 )); then
echo "Index does not depend on any commit (just amend?)" >&2
git reset --soft 'HEAD^'
else
echo "Index depends on more than one commit in this branch:" >&2
for b in $deps; do
echo $b
git log -n 1 --oneline $b
done
git reset --soft 'HEAD^'
fi