Skip to content

Commit 1a16363

Browse files
committed
Refactor prompt handling and error reporting in git-context script
- Simplify prompt file path resolution - Improve error handling for prompt file loading - Update help text to remove redundant path resolution explanation - Redirect error messages to stderr
1 parent 93bcd0b commit 1a16363

File tree

1 file changed

+4
-13
lines changed

1 file changed

+4
-13
lines changed

git-context

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,23 +15,14 @@ INCLUDE_PROMPT=true
1515
while [[ "$#" -gt 0 ]]; do
1616
case $1 in
1717
--recent-commits=*) RECENT_COMMITS="${1#*=}"; shift ;;
18-
--prompt=*)
19-
# If the path is relative and doesn't start with /, treat it as relative to script dir
20-
if [[ "${1#*=}" != /* ]]; then
21-
PROMPT_FILE="$SCRIPT_DIR/${1#*=}"
22-
else
23-
PROMPT_FILE="${1#*=}"
24-
fi
25-
shift
26-
;;
18+
--prompt=*) PROMPT_FILE="${1#*=}"; shift ;;
2719
--no-prompt) INCLUDE_PROMPT=false; shift ;;
2820
--help|-h)
2921
echo "Usage: git-context [options]"
3022
echo ""
3123
echo "Options:"
3224
echo " --recent-commits=<num> Show most recent N commits for context (default: 3)"
3325
echo " --prompt=<file> Use custom commit message prompt from file (default: prompts/commit_prompt.txt)"
34-
echo " (Relative paths will be resolved from the script's directory)"
3526
echo " --no-prompt Don't include commit message prompt"
3627
echo " --help, -h Show this help message"
3728
exit 0
@@ -42,7 +33,7 @@ done
4233

4334
# Ensure we're in a git repository
4435
if ! git rev-parse --is-inside-work-tree > /dev/null 2>&1; then
45-
echo "Error: Not a git repository"
36+
echo "Error: Not a git repository" >&2
4637
exit 1
4738
fi
4839

@@ -120,8 +111,8 @@ if [ "$INCLUDE_PROMPT" = true ]; then
120111
if [ -f "$PROMPT_FILE" ]; then
121112
cat "$PROMPT_FILE"
122113
else
123-
echo "Please write a clear and concise commit message that explains WHAT changes were made and WHY they were necessary."
124-
echo "Focus on the purpose and impact of the changes, not just the technical details."
114+
echo "Error: Prompt file not found: $PROMPT_FILE" >&2
115+
exit 1
125116
fi
126117
echo ""
127118
fi

0 commit comments

Comments
 (0)