fix: Move improvements via ShellCheck (#1075)

This commit is contained in:
Edwin Kofler 2023-09-21 20:57:48 -07:00 committed by GitHub
parent d2dde69d14
commit e793f8979b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 23 additions and 11 deletions

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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"
@ -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}- \

View file

@ -67,6 +67,7 @@ _git_effort(){
case "$cur" in
--*)
# shellcheck disable=SC2154
__gitcomp "
--above
$__git_log_common_options
@ -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(){