Added keyboard shortcut to append [ ci skip ] to commit message when committing all files
This commit is contained in:
@@ -91,8 +91,9 @@ git_tag_alias="gt"
|
||||
# ----------------------------------------------
|
||||
# Keyboard shortcuts are on by default. Set this to 'false' to disable them.
|
||||
git_keyboard_shortcuts_enabled="true"
|
||||
git_commit_all_keys="\C-x " # CTRL+x, SPACE
|
||||
git_add_and_commit_keys="\C-xc" # CTRL+x, c
|
||||
git_commit_all_keys="\C-x " # CTRL+x, SPACE
|
||||
git_add_and_commit_keys="\C-xc" # CTRL+x, c
|
||||
git_commit_all_with_ci_skip_keys="\C-xv" # CTRL+x, v (Appends [ci skip] to commit message)
|
||||
|
||||
|
||||
# Shell Command Wrapping
|
||||
|
||||
@@ -27,11 +27,13 @@ if [[ "$git_keyboard_shortcuts_enabled" = "true" ]]; then
|
||||
# Uses emacs style keybindings, so vi mode is not supported for now
|
||||
if ! set -o | grep -q '^vi .*on$'; then
|
||||
if [[ $shell == "zsh" ]]; then
|
||||
_bind "$git_commit_all_keys" " git_commit_all""\n"
|
||||
_bind "$git_add_and_commit_keys" " \033[1~ git_add_and_commit ""\n"
|
||||
_bind "$git_commit_all_keys" " git_commit_all""\n"
|
||||
_bind "$git_add_and_commit_keys" " \033[1~ git_add_and_commit ""\n"
|
||||
_bind "$git_commit_all_with_ci_skip_keys" " \033[1~ APPEND='[ci skip]' git_commit_all ""\n"
|
||||
else
|
||||
_bind "$git_commit_all_keys" "\" git_commit_all\n\""
|
||||
_bind "$git_add_and_commit_keys" "\"\033[1~ git_add_and_commit \n\""
|
||||
_bind "$git_commit_all_keys" "\" git_commit_all\n\""
|
||||
_bind "$git_add_and_commit_keys" "\"\033[1~ git_add_and_commit \n\""
|
||||
_bind "$git_commit_all_with_ci_skip_keys" "\"\033[1~ APPEND='[ci skip]' git_commit_all \n\""
|
||||
fi
|
||||
fi
|
||||
|
||||
|
||||
@@ -189,6 +189,8 @@ git_commit_prompt() {
|
||||
|
||||
if [ -n "$commit_msg" ]; then
|
||||
eval $@ # run any prequisite commands
|
||||
# Add $APPEND to commit message, if given. (Used to append things like [ci skip] for Travis CI)
|
||||
if [ -n "$APPEND" ]; then commit_msg="$commit_msg $APPEND"; fi
|
||||
echo $commit_msg | git commit -F - | tail -n +2
|
||||
else
|
||||
echo -e "\033[0;31mAborting commit due to empty commit message.\033[0m"
|
||||
@@ -210,7 +212,10 @@ git_commit_all() {
|
||||
fail_if_not_git_repo || return 1
|
||||
changes=$(git status --porcelain | wc -l)
|
||||
if [ "$changes" -gt 0 ]; then
|
||||
echo -e "\033[0;33mCommitting all files (\033[0;31m$changes\033[0;33m)\033[0m"
|
||||
if [ -n "$APPEND" ]; then
|
||||
local appending=" | \033[0;36mappending '\033[1;36m$APPEND\033[0;36m' to commit message.\033[0m"
|
||||
fi
|
||||
echo -e "\033[0;33mCommitting all files (\033[0;31m$changes\033[0;33m)\033[0m$appending"
|
||||
git_commit_prompt "git add -A"
|
||||
else
|
||||
echo "# No changed files to commit."
|
||||
@@ -229,4 +234,3 @@ git_add_and_commit() {
|
||||
echo "# No staged changes to commit."
|
||||
fi
|
||||
}
|
||||
|
||||
|
||||
@@ -234,9 +234,9 @@ test_git_commit_prompt() {
|
||||
commit_msg="\"Nathan's git commit prompt function!\""
|
||||
dbl_escaped_msg="\\\\\"Nathan's git commit prompt function\"'"'!'"'\"\\\\\""
|
||||
# Create temporary history file
|
||||
HISTFILE=$(mktemp -t scm_breeze.XXXXXXXXXX)
|
||||
HISTFILESIZE=1000
|
||||
HISTSIZE=1000
|
||||
export HISTFILE=$(mktemp -t scm_breeze.XXXXXXXXXX)
|
||||
export HISTFILESIZE=1000
|
||||
export HISTSIZE=1000
|
||||
|
||||
touch a b c d
|
||||
git add . > /dev/null
|
||||
@@ -252,12 +252,48 @@ test_git_commit_prompt() {
|
||||
assertIncludes "$git_show_output" "$commit_msg"
|
||||
|
||||
# Test that history was appended correctly.
|
||||
if [[ $shell != "zsh" ]]; then history -n; fi # Reload bash history
|
||||
test_history="$(history)"
|
||||
if [[ $shell == "zsh" ]]; then
|
||||
test_history="$(history)"
|
||||
else
|
||||
test_history="$(cat $HISTFILE)"
|
||||
fi
|
||||
assertIncludes "$test_history" "$commit_msg"
|
||||
assertIncludes "$test_history" "git commit -m \"$dbl_escaped_msg\""
|
||||
}
|
||||
|
||||
test_git_commit_prompt_with_append() {
|
||||
setupTestRepo
|
||||
|
||||
commit_msg="Updating README, no build please"
|
||||
|
||||
# Create temporary history file
|
||||
HISTFILE=$(mktemp -t scm_breeze.XXXXXXXXXX)
|
||||
HISTFILESIZE=1000
|
||||
HISTSIZE=1000
|
||||
|
||||
touch a b c
|
||||
git add . > /dev/null
|
||||
|
||||
# Zsh 'vared' doesn't handle input via pipe, so replace with function that reads into commit_msg variable.
|
||||
function vared(){ read commit_msg; }
|
||||
|
||||
# Test the git commit prompt, by piping a commit message
|
||||
# instead of user input.
|
||||
echo "$commit_msg" | APPEND="[ci skip]" git_commit_prompt > /dev/null
|
||||
|
||||
git_show_output=$(git show --oneline --name-only)
|
||||
assertIncludes "$git_show_output" "$commit_msg \[ci skip\]"
|
||||
|
||||
# Test that history was appended correctly.
|
||||
if [[ $shell == "zsh" ]]; then
|
||||
test_history="$(history)"
|
||||
else
|
||||
test_history="$(cat $HISTFILE)"
|
||||
fi
|
||||
assertIncludes "$test_history" "$commit_msg \[ci skip\]"
|
||||
assertIncludes "$test_history" "git commit -m \"$commit_msg \[ci skip\]\""
|
||||
}
|
||||
|
||||
test_adding_files_with_spaces() {
|
||||
setupTestRepo
|
||||
|
||||
|
||||
Reference in New Issue
Block a user