Skip to content

Commit

Permalink
Define git functions with parentheses instead of curly braces, so tha…
Browse files Browse the repository at this point in the history
…t we can press Ctrl+C to quit the commit prompt without terminating the shell session. (Parentheses run the function in a subshell.)
  • Loading branch information
ndbroadbent committed Oct 29, 2022
1 parent 6c85b86 commit 136fb6b
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions lib/git/status_shortcuts.sh
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ theirs(){ _git_resolve_merge_conflict "their" "$@"; }
# * Execute prerequisite commands if message given, abort if not
# * Pipe commit message to 'git commit'
# * Add escaped commit command and unescaped message to bash history.
git_commit_prompt() {
git_commit_prompt() (
local commit_msg
local saved_commit_msg
if [ -f "/tmp/.git_commit_message~" ]; then
Expand Down Expand Up @@ -268,10 +268,10 @@ git_commit_prompt() {
# Delete saved commit message if commit was successful
rm -f "/tmp/.git_commit_message~"
fi
}
)

# Prompt for commit message, then commit all modified and untracked files.
git_commit_all() {
git_commit_all() (
fail_if_not_git_repo || return 1
changes=$(git status --porcelain | wc -l | tr -d ' ')
if [ "$changes" -gt 0 ]; then
Expand All @@ -283,10 +283,10 @@ git_commit_all() {
else
echo "# No changed files to commit."
fi
}
)

# Add paths or expanded args if any given, then commit all staged changes.
git_add_and_commit() {
git_add_and_commit() (
fail_if_not_git_repo || return 1
git_silent_add_shortcuts "$@"
changes=$(git diff --cached --numstat | wc -l)
Expand All @@ -296,4 +296,4 @@ git_add_and_commit() {
else
echo "# No staged changes to commit."
fi
}
)
Empty file added test.sh
Empty file.

0 comments on commit 136fb6b

Please sign in to comment.