Skip to content

Commit f28ad39

Browse files
committed
feat(gitutils): ✨ improve emoji fix script
1 parent 633ea81 commit f28ad39

2 files changed

Lines changed: 24 additions & 2 deletions

File tree

src/gitutils/_git-fix-emoji.sh

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@
33
# Function to print help and manage arguments
44
eval $(
55
zz_args "Fix git emoji" $0 "$@" <<-help
6-
f - force allow overwritting pushed history
7-
- sha sha sha commit to fix from after
6+
f - force allow overwritting pushed history
7+
p - push push changes after rewriting history
8+
- sha sha sha commit to fix from after
89
help
910
)
1011

@@ -14,6 +15,12 @@ cd "$(git rev-parse --show-toplevel)" >/dev/null
1415
# Fetch updates from the remote repository
1516
git fetch --progress --prune --recurse-submodules=no origin >/dev/null
1617

18+
# Make sure we don't have uncommitted changes
19+
if ! git diff-index --quiet HEAD --; then
20+
zz_log e "You have uncommitted changes. Please commit or stash them before running this script."
21+
exit 1
22+
fi
23+
1724
# Retrieve the commit SHA to fixup
1825
sha=$(git getcommit $force $sha)
1926

@@ -25,3 +32,14 @@ git filter-branch --msg-filter 'npx --yes devmoji -t "$(cat)"' --tag-name-filter
2532
rm -rf .git/refs/original/
2633
git reflog expire --expire=now --all
2734
git gc --prune=now
35+
36+
# Push changes if the push flag is set
37+
if [ "$push" = true ]; then
38+
if [ "$force" = true ]; then
39+
git push --force --tags origin 'refs/heads/*'
40+
else
41+
git push --force-with-lease --tags origin 'refs/heads/*'
42+
fi
43+
fi
44+
45+
zz_log s "Git emoji fixup completed successfully."

src/gitutils/alias.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,10 @@
8787
"cmd": "git rev-parse --git-dir | grep -q rebase-merge || git rev-parse --git-dir | grep -q rebase-apply",
8888
"help": "Check if a rebase is in progress."
8989
},
90+
"isUncommited": {
91+
"cmd": "git fetch --progress --prune --recurse-submodules=no origin >/dev/null && git diff-index --quiet HEAD -- && exit 0 || exit 1",
92+
"help": "Check if file has uncommitted changes."
93+
},
9094
"pf": {
9195
"cmd": "git push --force-with-lease $1",
9296
"help": "Push with force-with-lease."

0 commit comments

Comments
 (0)