1
1
#! /bin/sh
2
2
3
+ set -e
4
+
5
+ # Source colors script
6
+ . zz_colors
7
+
8
+ # Function to print help and manage arguments
9
+ eval $(
10
+ zz_args " Fix git history" $0 " $@ " << -help
11
+ f - force allow overwritting pushed history
12
+ - sha sha sha commit to fixup
13
+ help
14
+ )
15
+
3
16
# # Do not fixup if staged files contains composer.lock or package-lock.json
4
17
if [ -n " $( git diff --cached --name-only | grep -E ' composer.lock|package-lock.json' ) " ]; then
5
18
echo ' Packages lock file are staged, fixup is not allowed.'
@@ -12,43 +25,32 @@ cd "$(git rev-parse --show-toplevel)" >/dev/null
12
25
# ### Integrate modifications from remote
13
26
git fetch --progress --prune --recurse-submodules=no origin > /dev/null
14
27
15
- # ### Display help
16
- if [ " $1 " = ' --help' ]; then
17
- echo ' Usage: git fixup [--force|<commit>]'
18
- exit 0
19
- fi
20
-
21
28
# ### Check if fixup commit exists
22
- echo ' Check if fixup commit exists...'
23
- if ! git isFixup; then
24
-
25
- # # Do not fixup if no files are staged
26
- if [ -z " $( git diff --cached --name-only) " ]; then
27
- echo ' No files are staged, fixup is not allowed.'
28
- exit 1
29
- fi
30
-
31
- # ### Get commit to fixup
32
-
33
- sha=$( git getcommit " $@ " )
29
+ if git isFixup; then
30
+ zz_log e ' Fixup commit found, please continue rebasing...'
31
+ exit 1
32
+ fi
34
33
35
- # ### Display commit to fixup
36
- echo ' Fixup commit given:' $sha
34
+ # # Do not fixup if no files are staged
35
+ if [ -z " $( git diff --cached --name-only) " ]; then
36
+ zz_log e ' No files are staged, fixup is not allowed.'
37
+ exit 1
38
+ fi
37
39
38
- # # Create fixup commit and exit if commit is not done
39
- if ! git commit --fixup $sha --no-verify; then
40
- echo ' Fixup commit failed...'
41
- exit 1
42
- fi
40
+ # ### Get commit to fixup
41
+ sha=$( git getcommit $sha )
43
42
44
- # ### Start rebase
45
- git rebase -i --autosquash $sha ~ --autostash --no-verify --exec ' [ -f .git/hooks/pre-commit ] && (.git/hooks/pre-commit --name-only HEAD HEAD~1 && git commit --amend --no-edit --no-verify) || true'
46
- else
47
- echo -e " \e[32mExisting !fixup commit found. Continue rebasing...\e[0m"
43
+ # ### Display commit to fixup
44
+ zz_log i " Fixup commit given: $sha "
48
45
49
- # ### Stage all changes
50
- git add --update && git rebase --continue
46
+ # # Create fixup commit and exit if commit is not done
47
+ if ! git commit --fixup $sha --no-verify; then
48
+ zz_log e ' Fixup commit failed...'
49
+ exit 1
51
50
fi
52
51
52
+ # ### Start rebase
53
+ git rebase -i --autosquash $sha ~ --autostash --no-verify --exec ' [ -f .git/hooks/pre-commit ] && (.git/hooks/pre-commit --name-only HEAD HEAD~1 && git commit --amend --no-edit --no-verify) || true'
54
+
53
55
# ### Back to previous directory
54
56
cd - > /dev/null
0 commit comments