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:
@@ -209,7 +209,7 @@ theirs(){ _git_resolve_merge_conflict "their" "$@"; }
|
|||||||
# * Execute prerequisite commands if message given, abort if not
|
# * Execute prerequisite commands if message given, abort if not
|
||||||
# * Pipe commit message to 'git commit'
|
# * Pipe commit message to 'git commit'
|
||||||
# * Add escaped commit command and unescaped message to bash history.
|
# * Add escaped commit command and unescaped message to bash history.
|
||||||
git_commit_prompt() {
|
git_commit_prompt() (
|
||||||
local commit_msg
|
local commit_msg
|
||||||
local saved_commit_msg
|
local saved_commit_msg
|
||||||
if [ -f "/tmp/.git_commit_message~" ]; then
|
if [ -f "/tmp/.git_commit_message~" ]; then
|
||||||
@@ -268,10 +268,10 @@ git_commit_prompt() {
|
|||||||
# Delete saved commit message if commit was successful
|
# Delete saved commit message if commit was successful
|
||||||
rm -f "/tmp/.git_commit_message~"
|
rm -f "/tmp/.git_commit_message~"
|
||||||
fi
|
fi
|
||||||
}
|
)
|
||||||
|
|
||||||
# Prompt for commit message, then commit all modified and untracked files.
|
# Prompt for commit message, then commit all modified and untracked files.
|
||||||
git_commit_all() {
|
git_commit_all() (
|
||||||
fail_if_not_git_repo || return 1
|
fail_if_not_git_repo || return 1
|
||||||
changes=$(git status --porcelain | wc -l | tr -d ' ')
|
changes=$(git status --porcelain | wc -l | tr -d ' ')
|
||||||
if [ "$changes" -gt 0 ]; then
|
if [ "$changes" -gt 0 ]; then
|
||||||
@@ -283,10 +283,10 @@ git_commit_all() {
|
|||||||
else
|
else
|
||||||
echo "# No changed files to commit."
|
echo "# No changed files to commit."
|
||||||
fi
|
fi
|
||||||
}
|
)
|
||||||
|
|
||||||
# Add paths or expanded args if any given, then commit all staged changes.
|
# 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
|
fail_if_not_git_repo || return 1
|
||||||
git_silent_add_shortcuts "$@"
|
git_silent_add_shortcuts "$@"
|
||||||
changes=$(git diff --cached --numstat | wc -l)
|
changes=$(git diff --cached --numstat | wc -l)
|
||||||
@@ -296,4 +296,4 @@ git_add_and_commit() {
|
|||||||
else
|
else
|
||||||
echo "# No staged changes to commit."
|
echo "# No staged changes to commit."
|
||||||
fi
|
fi
|
||||||
}
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user