Skip to content

Commit

Permalink
fix: Move improvements via ShellCheck (#1075)
Browse files Browse the repository at this point in the history
  • Loading branch information
hyperupcall authored Sep 22, 2023
1 parent d2dde69 commit e793f89
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 11 deletions.
18 changes: 12 additions & 6 deletions bin/git-bulk
Original file line number Diff line number Diff line change
Expand Up @@ -22,27 +22,33 @@ usage() {
echo 1>&2 " git bulk --listall"
}

cdfail() {
echo 1>&2 "failed to change directory: $1"
exit 1
}

# add another workspace to global git config
function addworkspace {
git config --global bulkworkspaces."$wsname" "$wsdir";
if [ -n "$source" ]; then
git config --global bulkworkspaces."$wsname" "$wsdir";
if [ -n "$source" ]; then
if [ ! -d "$wsdir" ]; then echo 1>&2 "Path of workspace doesn't exist, make it first."; exit 1; fi
regex='http(s)?://|ssh://|(git@)?.*:.*/.*'
if [[ "$source" =~ $regex ]]; then
pushd "$wsdir" > /dev/null
pushd "$wsdir" > /dev/null || cdfail "$wsdir"
git clone "$source"
popd > /dev/null
popd > /dev/null || cdfail "$OLDPWD"
else
source=$(realpath "$source" 2>/dev/null)
if [ -f "$source" ]; then
pushd "$wsdir" > /dev/null
pushd "$wsdir" > /dev/null || cdfail "$wsdir"
while IFS= read -r line; do
if [ -n "$line" ]; then
# the git clone command to take the complete line in the repository.txt as separate argument. This facilitated the cloning of the repository with a custom folder name.
# shellcheck disable=SC2086
git clone $line;
fi
done < "$source"
popd > /dev/null
popd > /dev/null || cdfail "$OLDPWD"
else
echo 1>&2 "format of URL or file unknown"
fi
Expand Down
2 changes: 2 additions & 0 deletions bin/git-changelog
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,8 @@ _fetchCommitRange() {
local start_tag="$2"
local final_tag="$3"

# This shellcheck disable is applied to the whole if-body
# shellcheck disable=SC2086
if [[ "$list_all" == true ]]; then
git log $GIT_LOG_OPTS --pretty=format:"${CUR_GIT_LOG_FORMAT}"
elif [[ -n "$final_tag" && "$start_tag" == "null" ]]; then
Expand Down
3 changes: 2 additions & 1 deletion bin/git-force-clone
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,8 @@ main() {
git reset --hard "origin/${branch}"

# Delete all other branches
branches=$(git branch | grep -v \* | xargs)
# shellcheck disable=SC2063
branches=$(git branch | grep -v '*' | xargs)
if [ -n "${branches}" ]; then
git branch -D "${branches}"
fi
Expand Down
5 changes: 2 additions & 3 deletions bin/git-psykorebase
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,9 @@ else

git checkout "${PRIMARY_BRANCH}" || exit 41
git checkout -b "${TARGET_BRANCH}" || exit 42
git merge "${SECONDARY_BRANCH}" ${FF} \
-m "Psycho-rebased branch ${SECONDARY_BRANCH} on top of ${PRIMARY_BRANCH}"

if [[ $? == 0 ]]; then
if git merge "${SECONDARY_BRANCH}" ${FF} \
-m "Psycho-rebased branch ${SECONDARY_BRANCH} on top of ${PRIMARY_BRANCH}"; then
git branch -d "${SECONDARY_BRANCH}" || exit 43
git branch -m "${TARGET_BRANCH}" "${SECONDARY_BRANCH}" || exit 44
else
Expand Down
3 changes: 3 additions & 0 deletions bin/git-utimes
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@ if [ "$1" = "--touch" ]; then
fi
for f; do
git_s=$(git --no-pager log --no-renames --pretty=format:%ct -1 @ -- "$f" 2>/dev/null)
# shellcheck disable=SC2086
mod_s=$(stat $stat_flags "$f" 2>/dev/null)
if [ -n "$git_s" ] && [ -n "$mod_s" ] && [ "$mod_s" -ne "$git_s" ]; then
if [ "$mod_s" -gt "$git_s" ] || [ -z "$newer_flag" ]; then
# shellcheck disable=SC2086
t=$(date $date_flags$git_s '+%Y%m%d%H%M.%S')
echo "+ touch -h -t $t $f" >&2
touch -h -t "$t" "$f"
Expand All @@ -35,6 +37,7 @@ else
# don't touch files that have been modified in the worktree or index
# bsd doesn't have `-z` option for `comm` and `cut`, so use `tr` as work around
prefix="$(git rev-parse --show-prefix) "
# shellcheck disable=SC2086
comm -23 <(git ls-tree -z -r --name-only --full-name @ | tr '\0' '\n' | sort) \
<(git status -z --porcelain | tr '\0' '\n' | cut -c 4- | sort) \
| cut -c ${#prefix}- \
Expand Down
3 changes: 2 additions & 1 deletion etc/bash_completion.sh
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ _git_effort(){

case "$cur" in
--*)
# shellcheck disable=SC2154
__gitcomp "
--above
$__git_log_common_options
Expand All @@ -82,7 +83,7 @@ _git_extras(){
}

__git_extras_workflow(){
__gitcomp "$(__git_heads | grep -- ^$1/ | sed s/^$1\\///g) finish"
__gitcomp "$(__git_heads | grep -- "^$1/" | sed s/^"$1"\\///g) finish"
}

_git_feature(){
Expand Down

0 comments on commit e793f89

Please sign in to comment.