Fix git checkout,diff,reset,rm in deleted directories, if pwd is in git dir
This commit is contained in:
@@ -26,8 +26,10 @@ if type hub > /dev/null 2>&1; then export _git_cmd="hub"; fi
|
||||
function git(){
|
||||
# Only expand args for git commands that deal with paths or branches
|
||||
case $1 in
|
||||
checkout|commit|rm|blame|diff|add|log|rebase|reset|merge)
|
||||
commit|blame|add|log|rebase|merge)
|
||||
exec_scmb_expand_args "$_git_cmd" "$@";;
|
||||
checkout|diff|rm|reset)
|
||||
exec_scmb_expand_args --relative "$_git_cmd" "$@";;
|
||||
branch)
|
||||
_scmb_git_branch_shortcuts "${@:2}";;
|
||||
*)
|
||||
@@ -89,14 +91,13 @@ if [ "$git_setup_aliases" = "yes" ]; then
|
||||
__git_alias "$git_checkout_alias" "git" "checkout"
|
||||
__git_alias "$git_commit_alias" "git" "commit"
|
||||
__git_alias "$git_commit_verbose_alias" "git" "commit" "--verbose"
|
||||
__git_alias "$git_reset_alias" "git" "reset"
|
||||
__git_alias "$git_reset_del_alias" "git" "reset" "--"
|
||||
__git_alias "$git_reset_alias" "git" "reset" "--"
|
||||
__git_alias "$git_reset_hard_alias" "git" "reset" "--hard"
|
||||
__git_alias "$git_rm_alias" "git" "rm"
|
||||
__git_alias "$git_blame_alias" "git" "blame"
|
||||
__git_alias "$git_diff_alias" "git" "diff"
|
||||
__git_alias "$git_diff_alias" "git" "diff" "--"
|
||||
__git_alias "$git_diff_word_alias" "git" "diff" "--word-diff"
|
||||
__git_alias "$git_diff_cached_alias" "git" "diff" "--cached"
|
||||
__git_alias "$git_diff_cached_alias" "git" "diff" "--cached --"
|
||||
__git_alias "$git_add_patch_alias" "git" "add" "-p"
|
||||
__git_alias "$git_add_updated_alias" "git" "add" "-u"
|
||||
__git_alias "$git_difftool_alias" "git" "difftool"
|
||||
|
||||
@@ -116,21 +116,28 @@ git_show_affected_files(){
|
||||
# * git_status_shortcuts() - git status implementation
|
||||
# * git_show_affected_files() - shows files affected by a given SHA1, etc.
|
||||
scmb_expand_args() {
|
||||
# Check for --relative param
|
||||
if [ "$1" = "--relative" ]; then
|
||||
local relative=1
|
||||
shift
|
||||
fi
|
||||
|
||||
first=1
|
||||
OLDIFS="$IFS"; IFS=" " # We need to split on spaces to loop over expanded range
|
||||
for arg in "$@"; do
|
||||
if [[ "$arg" =~ ^[0-9]{0,4}$ ]] ; then # Substitute $e{*} variables for any integers
|
||||
if [ "$first" -eq 1 ]; then first=0; else printf '\t'; fi
|
||||
if [ -e "$arg" ]; then
|
||||
# Don't expand files or directories with numeric names
|
||||
printf '%s' "$arg"
|
||||
else
|
||||
eval printf '%s' "\"\$$git_env_char$arg\""
|
||||
_print_path "$relative" "$git_env_char$arg"
|
||||
fi
|
||||
elif [[ "$arg" =~ ^[0-9]+-[0-9]+$ ]]; then # Expand ranges into $e{*} variables
|
||||
|
||||
for i in $(eval echo {${arg/-/..}}); do
|
||||
if [ "$first" -eq 1 ]; then first=0; else printf '\t'; fi
|
||||
eval printf '%s' "\"\$$git_env_char$i\""
|
||||
_print_path "$relative" "$git_env_char$i"
|
||||
done
|
||||
else # Otherwise, treat $arg as a normal string.
|
||||
if [ "$first" -eq 1 ]; then first=0; else printf '\t'; fi
|
||||
@@ -140,9 +147,19 @@ scmb_expand_args() {
|
||||
IFS="$OLDIFS"
|
||||
}
|
||||
|
||||
_print_path() {
|
||||
if [ "$1" = 1 ]; then
|
||||
eval printf '%s' "\"\$$2\"" | sed -e "s%$(pwd)/%%" | awk '{printf("%s", $0)}'
|
||||
else
|
||||
eval printf '%s' "\"\$$2\""
|
||||
fi
|
||||
}
|
||||
|
||||
# Execute a command with expanded args, e.g. Delete files 6 to 12: $ ge rm 6-12
|
||||
# Fails if command is a number or range (probably not worth fixing)
|
||||
exec_scmb_expand_args() { eval "$(scmb_expand_args "$@" | sed -e "s/\([][()<>^ \"']\)/"'\\\1/g')"; }
|
||||
exec_scmb_expand_args() {
|
||||
eval "$(scmb_expand_args "$@" | sed -e "s/\([][()<>^ \"']\)/"'\\\1/g')"
|
||||
}
|
||||
|
||||
# Clear numbered env variables
|
||||
git_clear_vars() {
|
||||
|
||||
Reference in New Issue
Block a user