Skip to content

Commit

Permalink
Merge pull request #263 from HaleTom/quote-filenames
Browse files Browse the repository at this point in the history
Fix #167, #202, #204, #274 and a bunch of other goodies
  • Loading branch information
ghthor authored Sep 29, 2018
2 parents e5971cf + a8cf407 commit 7152788
Show file tree
Hide file tree
Showing 18 changed files with 320 additions and 145 deletions.
2 changes: 2 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ env:
- TEST_SHELLS=bash
- TEST_SHELLS=zsh

sudo: required

install:
- ./test/support/travisci_deps.sh

Expand Down
3 changes: 1 addition & 2 deletions lib/design.sh
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ design() {
local project=`basename $(pwd)`
local all_project_dirs="$design_base_dirs $design_av_dirs"
# Ensure design dir contains all subdirectories
IFS=$' \t\n'
local IFS=$' \t\n'
# Create root design dirs
for dir in $design_ext_dirs; do mkdir -p "$root_design_dir/$dir"; done
# Create project design dirs
Expand Down Expand Up @@ -102,6 +102,5 @@ design() {
printf "Invalid command.\n\n"
design
fi
unset IFS
}

4 changes: 2 additions & 2 deletions lib/git/aliases.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ unalias git > /dev/null 2>&1
unset -f git > /dev/null 2>&1

# Use the full path to git to avoid infinite loop with git function
export _git_cmd="$(\which git)"
export _git_cmd="$(bin_path git)"
# Wrap git with the 'hub' github wrapper, if installed (https://github.com/defunkt/hub)
if type hub > /dev/null 2>&1; then export _git_cmd="hub"; fi

Expand Down Expand Up @@ -71,7 +71,7 @@ __git_alias () {
alias_str="$1"; cmd_prefix="$2"; cmd="$3";
if [ $# -gt 2 ]; then
shift 3 2>/dev/null
cmd_args=$@
cmd_args=("$@")
fi

alias $alias_str="$cmd_prefix $cmd${cmd_args:+ }${cmd_args[*]}"
Expand Down
6 changes: 2 additions & 4 deletions lib/git/branch_shortcuts.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ function _scmb_git_branch_shortcuts {

# Use ruby to inject numbers into ls output
ruby -e "$( cat <<EOF
output = %x($_git_cmd branch --color=always $@)
output = %x($_git_cmd branch --color=always "$@")
line_count = output.lines.to_a.size
output.lines.each_with_index do |line, i|
spaces = (line_count > 9 && i < 9 ? " " : " ")
Expand All @@ -32,14 +32,12 @@ EOF
)"

# Set numbered file shortcut in variable
local e=1
IFS=$'\n'
local e=1 IFS=$'\n'
for branch in $($_git_cmd branch "$@" | sed "s/^[* ]\{2\}//"); do
export $git_env_char$e="$branch"
if [ "${scmbDebug:-}" = "true" ]; then echo "Set \$$git_env_char$e => $file"; fi
let e++
done
unset IFS
}

__git_alias "$git_branch_alias" "_scmb_git_branch_shortcuts" ""
Expand Down
5 changes: 2 additions & 3 deletions lib/git/fallback/status_shortcuts_shell.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
# --------------------------------------------------------------------
git_status_shortcuts() {
zsh_compat # Ensure shwordsplit is on for zsh
IFS=$'\n'
local IFS=$'\n'
local git_status="$(git status --porcelain 2> /dev/null)"
local i

Expand Down Expand Up @@ -95,7 +95,7 @@ git_status_shortcuts() {
fi
done

IFS=" "
local IFS=" "
grp_num=1
for heading in 'Changes to be committed' 'Unmerged paths' 'Changes not staged for commit' 'Untracked files'; do
# If no group specified as param, or specified group is current group
Expand All @@ -114,7 +114,6 @@ git_status_shortcuts() {
# so just use plain 'git status'
git status
fi
unset IFS
zsh_reset # Reset zsh environment to default
}
# Template function for 'git_status_shortcuts'.
Expand Down
9 changes: 8 additions & 1 deletion lib/git/helpers.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,11 @@ function fail_if_not_git_repo() {
return 1
fi
return 0
}
}

bin_path() {
if [[ -n ${ZSH_VERSION:-} ]];
then builtin whence -cp "$1" 2> /dev/null
else builtin type -P "$1"
fi
}
43 changes: 19 additions & 24 deletions lib/git/repo_index.sh
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@


function git_index() {
IFS=$'\n'
local IFS=$'\n'
if [ -z "$1" ]; then
# Just change to $GIT_REPO_DIR if no params given.
"cd" $GIT_REPO_DIR
Expand Down Expand Up @@ -103,7 +103,7 @@ function git_index() {
# --------------------
# Go to our base path
if [ -n "$base_path" ]; then
IFS=$' \t\n'
local IFS=$' \t\n'
# evaluate ~ if necessary
if [[ "$base_path" == "~"* ]]; then
base_path=$(eval echo ${base_path%%/*})/${base_path#*/}
Expand All @@ -116,7 +116,6 @@ function git_index() {
fi
fi
fi
unset IFS
}

_git_index_dirs_without_home() {
Expand All @@ -126,12 +125,11 @@ _git_index_dirs_without_home() {
# Recursively searches for git repos in $GIT_REPO_DIR
function _find_git_repos() {
# Find all unarchived projects
IFS=$'\n'
local IFS=$'\n'
for repo in $(find -L "$GIT_REPO_DIR" -maxdepth 5 -name ".git" -type d \! -wholename '*/archive/*'); do
echo ${repo%/.git} # Return project folder, with trailing ':'
_find_git_submodules $repo # Detect any submodules
done
unset IFS
}

# List all submodules for a git repo, if any.
Expand All @@ -146,11 +144,10 @@ function _find_git_submodules() {
function _rebuild_git_index() {
if [ "$1" != "--silent" ]; then echo -e "== Scanning $GIT_REPO_DIR for git repos & submodules..."; fi
# Get repos from src dir and custom dirs, then sort by basename
IFS=$'\n'
local IFS=$'\n'
for repo in $(echo -e "$(_find_git_repos)\n$(echo $GIT_REPOS | sed "s/:/\\\\n/g")"); do
echo $(basename $repo | sed "s/ /_/g"):$repo
done | sort -t ":" -k1,1 | cut -d ":" -f2- >| "$GIT_REPO_DIR/.git_index"
unset IFS

if [ "$1" != "--silent" ]; then
echo -e "===== Indexed $_bld_col$(_git_index_count)$_txt_col repos in $GIT_REPO_DIR/.git_index"
Expand Down Expand Up @@ -205,39 +202,39 @@ _git_index_update_all_branches() {
return
fi

local remotes merges branches
# zsh 5.0.2 requires local separate to assignment for arrays
local remote merge remotes merges branches
# Get branch configuration from .git/config
IFS=$'\n'
local IFS=$'\n'
for branch in $($GIT_BINARY branch 2> /dev/null | sed -e 's/.\{2\}\(.*\)/\1/'); do
# Skip '(no branch)'
if [[ "$branch" = "(no branch)" ]]; then continue; fi

local remote=$(git config --get branch.$branch.remote)
local merge=$(git config --get branch.$branch.merge)
remote=$(git config --get "branch.$branch.remote")
merge=$(git config --get "branch.$branch.merge")

# Ignore branch if remote and merge is not configured
if [[ -n "$remote" ]] && [[ -n "$merge" ]]; then
branches=(${branches[@]} "$branch")
remotes=(${remotes[@]} "$remote")
branches=("${branches[@]}" "$branch")
remotes=("${remotes[@]}" "$remote")
# Get branch from merge ref (refs/heads/master => master)
merges=(${merges[@]} "$(basename $merge)")
merges=("${merges[@]}" "$(basename "$merge")")
else
echo "=== Skipping $branch: remote and merge refs are not configured."
fi
done
unset IFS

# Update all remotes if there are any branches to update
if [ -n "${branches[*]}" ]; then git fetch --all 2> /dev/null; fi

local index=0
# Iterate over branches, and update those that can be fast-forwarded
for branch in ${branches[@]}; do
for branch in "${branches[@]}"; do
branch_rev="$(git rev-parse $branch)"
# Local branch can be fast-forwarded if revision is ancestor of remote revision, and not the same.
# (see http://stackoverflow.com/a/2934062/304706)
if [[ "$branch_rev" != "$(git rev-parse ${remotes[$index]}/${merges[$index]})" ]] && \
[[ "$(git merge-base $branch_rev ${remotes[$index]}/${merges[$index]})" = "$branch_rev" ]]; then
if [[ "$branch_rev" != "$(git rev-parse "${remotes[$index]}/${merges[$index]}")" ]] && \
[[ "$(git merge-base "$branch_rev" "${remotes[$index]}/${merges[$index]}")" = "$branch_rev" ]]; then
echo "=== Updating $branch branch in $base_path from ${remotes[$index]}/${merges[$index]}..."
# Checkout branch if we aren't already on it.
if [[ "$branch" != "$(parse_git_branch)" ]]; then git checkout $branch; fi
Expand Down Expand Up @@ -268,11 +265,11 @@ function _git_index_batch_cmd() {
cwd="$PWD"
if [ -n "$1" ]; then
echo -e "== Running command for $_bld_col$(_git_index_count)$_txt_col repos...\n"
unset IFS
local IFS=$'\n'
local base_path
for base_path in $(sed -e "s/--.*//" "$GIT_REPO_DIR/.git_index" | \grep . | sort); do
builtin cd "$base_path"
$@
"$@"
done
else
echo "Please give a command to run for all repos. (It may be useful to write your command as a function or script.)"
Expand All @@ -285,8 +282,7 @@ if [ $shell = 'bash' ]; then
# Bash tab completion function for git_index()
function _git_index_tab_completion() {
_check_git_index
local curw
IFS=$'\n'
local curw IFS=$'\n'
COMPREPLY=()
curw=${COMP_WORDS[COMP_CWORD]}

Expand All @@ -313,10 +309,9 @@ if [ $shell = 'bash' ]; then
else
COMPREPLY=($(compgen -W '$(sed -e "s:.*/::" -e "s:$:/:" "$GIT_REPO_DIR/.git_index" | sort)' -- $curw))
fi
unset IFS
return 0
}
else
else # Zsh tab completion function for git_index()
function _git_index_tab_completion() {
typeset -A opt_args
local state state_descr context line
Expand Down
Loading

0 comments on commit 7152788

Please sign in to comment.