Skip to content

Commit 4a137b6

Browse files
authored
Revert "chore: ignore -m if used."
1 parent 92d870f commit 4a137b6

File tree

1 file changed

+10
-45
lines changed

1 file changed

+10
-45
lines changed

commit

Lines changed: 10 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,73 +1,38 @@
11
#!/usr/bin/env bash
22
set -euo pipefail
33

4-
# Function to display help message
5-
show_help() {
4+
if [ -z "${1:-}" ] || [ "$1" = "-h" ] || [ "$1" = "--help" ]; then
65
echo -e "Create a commit prefixed with the current branch name.\n"
76
echo "Usage:"
8-
echo -e " commit MESSAGE [options]\n"
9-
echo -e " commit -m MESSAGE [options]\n"
10-
echo "Examples:"
11-
echo " commit \"Add new feature\" # Commit with branch-prefixed message"
12-
echo " commit -m \"Fix bug\" # Commit with branch-prefixed message using -m"
13-
echo " commit \"Refactor code\" --no-verify # Commit with branch-prefixed message, skip verification"
14-
echo " commit -m \"Update docs\" --no-verify # Commit with branch-prefixed message using -m, skip verification"
7+
echo -e " commit MESSAGE\n"
8+
echo "Example:"
9+
echo " commit \"Hello world!\""
1510
exit 1
16-
}
17-
18-
# Check for help flag
19-
if [ -z "${1:-}" ] || [ "$1" = "-h" ] || [ "$1" = "--help" ]; then
20-
show_help
21-
fi
22-
23-
# Initialize EXTRA_ARGS as an empty array
24-
EXTRA_ARGS=()
25-
26-
# Determine if -m is used, and capture the message accordingly
27-
if [ "$1" = "-m" ]; then
28-
if [ -z "${2:-}" ]; then
29-
echo "Error: Commit message cannot be empty."
30-
exit 1
31-
fi
32-
COMMIT_MESSAGE="$2"
33-
EXTRA_ARGS=("${@:3}")
34-
else
35-
COMMIT_MESSAGE="$1"
36-
EXTRA_ARGS=("${@:2}")
3711
fi
3812

3913
CURRENT_BRANCH="$(git symbolic-ref --short HEAD)"
4014
GIT_ROOT_DIRECTORY=$(git rev-parse --show-toplevel)
4115
IGNORED_BRANCHES=("dev" "master" "main" "qa" "uat" "staging")
4216
CUSTOM_IGNORED_PATH="$GIT_ROOT_DIRECTORY/.smart-commit-ignore"
4317

44-
# Add custom ignored branches if .smart-commit-ignore file exists
4518
if [ -f "$CUSTOM_IGNORED_PATH" ]; then
4619
CUSTOM_BRANCHES=$(cat "$CUSTOM_IGNORED_PATH")
4720
BRANCHES=($CUSTOM_BRANCHES)
4821
IGNORED_BRANCHES=(${IGNORED_BRANCHES[@]} ${BRANCHES[@]})
4922
fi
5023

51-
# Check if the current branch is in the ignored branches list
5224
IS_IGNORED=false
25+
5326
for branch in "${IGNORED_BRANCHES[@]}"; do
54-
if [ "$CURRENT_BRANCH" == "$branch" ]; then
27+
if [ "$CURRENT_BRANCH" == $branch ]; then
5528
IS_IGNORED=true
5629
break
57-
fi
30+
fi
5831
done
5932

60-
# Build the commit command dynamically to avoid empty strings
6133
if [ "$IS_IGNORED" == false ]; then
62-
if [ "${#EXTRA_ARGS[@]}" -eq 0 ]; then
63-
git commit -m "$CURRENT_BRANCH: $COMMIT_MESSAGE"
64-
else
65-
git commit -m "$CURRENT_BRANCH: $COMMIT_MESSAGE" "${EXTRA_ARGS[@]}"
66-
fi
34+
# Edit your config here
35+
git commit -m "$CURRENT_BRANCH: $1" ${@:2}
6736
else
68-
if [ "${#EXTRA_ARGS[@]}" -eq 0 ]; then
69-
git commit -m "$COMMIT_MESSAGE"
70-
else
71-
git commit -m "$COMMIT_MESSAGE" "${EXTRA_ARGS[@]}"
72-
fi
37+
git commit -m "$1" ${@:2}
7338
fi

0 commit comments

Comments
 (0)