Define git functions with parentheses instead of curly braces, so that we can press Ctrl+C to quit the commit prompt without terminating the shell session. (Parentheses run the function in a subshell.)

This commit is contained in:
Nathan Broadbent
2022-10-29 15:12:06 +13:00
parent 6c85b866af
commit 136fb6b4ee
2 changed files with 6 additions and 6 deletions

View File

@@ -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
@@ -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
@@ -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)
@@ -296,4 +296,4 @@ git_add_and_commit() {
else
echo "# No staged changes to commit."
fi
}
)

0
test.sh Normal file
View File