Skip to content

Commit 64c519e

Browse files
committed
fix: Move improvements via ShellCheck
1 parent f95e339 commit 64c519e

File tree

6 files changed

+23
-11
lines changed

6 files changed

+23
-11
lines changed

bin/git-bulk

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,27 +22,33 @@ usage() {
2222
echo 1>&2 " git bulk --listall"
2323
}
2424

25+
cdfail() {
26+
echo 1>&2 "failed to change directory: $1"
27+
exit 1
28+
}
29+
2530
# add another workspace to global git config
2631
function addworkspace {
27-
git config --global bulkworkspaces."$wsname" "$wsdir";
28-
if [ -n "$source" ]; then
32+
git config --global bulkworkspaces."$wsname" "$wsdir";
33+
if [ -n "$source" ]; then
2934
if [ ! -d "$wsdir" ]; then echo 1>&2 "Path of workspace doesn't exist, make it first."; exit 1; fi
3035
regex='http(s)?://|ssh://|(git@)?.*:.*/.*'
3136
if [[ "$source" =~ $regex ]]; then
32-
pushd "$wsdir" > /dev/null
37+
pushd "$wsdir" > /dev/null || cdfail "$wsdir"
3338
git clone "$source"
34-
popd > /dev/null
39+
popd > /dev/null || cdfail "$OLDPWD"
3540
else
3641
source=$(realpath "$source" 2>/dev/null)
3742
if [ -f "$source" ]; then
38-
pushd "$wsdir" > /dev/null
43+
pushd "$wsdir" > /dev/null || cdfail "$wsdir"
3944
while IFS= read -r line; do
4045
if [ -n "$line" ]; then
4146
# 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.
47+
# shellcheck disable=SC2086
4248
git clone $line;
4349
fi
4450
done < "$source"
45-
popd > /dev/null
51+
popd > /dev/null || cdfail "$OLDPWD"
4652
else
4753
echo 1>&2 "format of URL or file unknown"
4854
fi

bin/git-changelog

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,8 @@ _fetchCommitRange() {
146146
local start_tag="$2"
147147
local final_tag="$3"
148148

149+
# This shellcheck disable is applied to the whole if-body
150+
# shellcheck disable=SC2086
149151
if [[ "$list_all" == true ]]; then
150152
git log $GIT_LOG_OPTS --pretty=format:"${CUR_GIT_LOG_FORMAT}"
151153
elif [[ -n "$final_tag" && "$start_tag" == "null" ]]; then

bin/git-force-clone

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,8 @@ main() {
9191
git reset --hard "origin/${branch}"
9292

9393
# Delete all other branches
94-
branches=$(git branch | grep -v \* | xargs)
94+
# shellcheck disable=SC2063
95+
branches=$(git branch | grep -v '*' | xargs)
9596
if [ -n "${branches}" ]; then
9697
git branch -D "${branches}"
9798
fi

bin/git-psykorebase

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,9 @@ else
7373

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

79-
if [[ $? == 0 ]]; then
77+
if git merge "${SECONDARY_BRANCH}" ${FF} \
78+
-m "Psycho-rebased branch ${SECONDARY_BRANCH} on top of ${PRIMARY_BRANCH}"; then
8079
git branch -d "${SECONDARY_BRANCH}" || exit 43
8180
git branch -m "${TARGET_BRANCH}" "${SECONDARY_BRANCH}" || exit 44
8281
else

bin/git-utimes

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,11 @@ if [ "$1" = "--touch" ]; then
1717
fi
1818
for f; do
1919
git_s=$(git --no-pager log --no-renames --pretty=format:%ct -1 @ -- "$f" 2>/dev/null)
20+
# shellcheck disable=SC2086
2021
mod_s=$(stat $stat_flags "$f" 2>/dev/null)
2122
if [ -n "$git_s" ] && [ -n "$mod_s" ] && [ "$mod_s" -ne "$git_s" ]; then
2223
if [ "$mod_s" -gt "$git_s" ] || [ -z "$newer_flag" ]; then
24+
# shellcheck disable=SC2086
2325
t=$(date $date_flags$git_s '+%Y%m%d%H%M.%S')
2426
echo "+ touch -h -t $t $f" >&2
2527
touch -h -t "$t" "$f"
@@ -35,6 +37,7 @@ else
3537
# don't touch files that have been modified in the worktree or index
3638
# bsd doesn't have `-z` option for `comm` and `cut`, so use `tr` as work around
3739
prefix="$(git rev-parse --show-prefix) "
40+
# shellcheck disable=SC2086
3841
comm -23 <(git ls-tree -z -r --name-only --full-name @ | tr '\0' '\n' | sort) \
3942
<(git status -z --porcelain | tr '\0' '\n' | cut -c 4- | sort) \
4043
| cut -c ${#prefix}- \

etc/bash_completion.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ _git_effort(){
6767

6868
case "$cur" in
6969
--*)
70+
# shellcheck disable=SC2154
7071
__gitcomp "
7172
--above
7273
$__git_log_common_options
@@ -82,7 +83,7 @@ _git_extras(){
8283
}
8384

8485
__git_extras_workflow(){
85-
__gitcomp "$(__git_heads | grep -- ^$1/ | sed s/^$1\\///g) finish"
86+
__gitcomp "$(__git_heads | grep -- "^$1/" | sed s/^"$1"\\///g) finish"
8687
}
8788

8889
_git_feature(){

0 commit comments

Comments
 (0)