Skip to content

Commit fa540b1

Browse files
committed
chore: 🔧 refactor gitutils
1 parent 707b2e6 commit fa540b1

File tree

2 files changed

+34
-32
lines changed

2 files changed

+34
-32
lines changed

src/gitutils/_fixup.sh

Lines changed: 33 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,18 @@
11
#!/bin/sh
22

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+
316
## Do not fixup if staged files contains composer.lock or package-lock.json
417
if [ -n "$(git diff --cached --name-only | grep -E 'composer.lock|package-lock.json')" ]; then
518
echo 'Packages lock file are staged, fixup is not allowed.'
@@ -12,43 +25,32 @@ cd "$(git rev-parse --show-toplevel)" >/dev/null
1225
#### Integrate modifications from remote
1326
git fetch --progress --prune --recurse-submodules=no origin >/dev/null
1427

15-
#### Display help
16-
if [ "$1" = '--help' ]; then
17-
echo 'Usage: git fixup [--force|<commit>]'
18-
exit 0
19-
fi
20-
2128
#### 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
3433

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
3739

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)
4342

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"
4845

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
5150
fi
5251

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+
5355
#### Back to previous directory
5456
cd - >/dev/null

src/gitutils/devcontainer-feature.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"id": "gitutils",
33
"name": "Git Aliases",
44
"description": "A feature to add useful Git aliases to your shell.",
5-
"version": "5.4.3",
5+
"version": "5.5.0",
66
"dependsOn": {
77
"ghcr.io/devcontainers/features/node:1": "lts",
88
"ghcr.io/tomgrv/devcontainer-features/common-utils:3": {

0 commit comments

Comments
 (0)