diff --git a/.codeclimate.yml b/.codeclimate.yml new file mode 100644 index 000000000..1f3581af5 --- /dev/null +++ b/.codeclimate.yml @@ -0,0 +1,55 @@ +--- +engines: + pep8: + enabled: true + duplication: + enabled: true + config: + languages: + - "python" + fixme: + enabled: true + exclude_paths: + - config/engines.yml + pep8: + enabled: true + checks: + E111: + enabled: false + E501: + enabled: false + markdownlint: + enabled: true + checks: + MD004: + enabled: false + MD007: + enabled: false + MD013: + enabled: false + MD026: + enabled: false + MD029: + enabled: false + MD033: + enabled: false + MD034: + enabled: false + MD038: + enabled: false + shellcheck: + enabled: true +ratings: + paths: + - "bin/**/*" + - "**.py" + - "**.md" +exclude_paths: + - .bundle/ + - benchmarks/**/* + - build/ + - dist/ + - include/**/* + - lib/**/* + - License.md + - spec/**/* diff --git a/Contributing.md b/Contributing.md index 13fb843d2..d183f2e47 100644 --- a/Contributing.md +++ b/Contributing.md @@ -1,8 +1,8 @@ -## Contributing +# Contributing **git-extra-commands** is a collection of helper scripts for git and links to git-related articles. -# Contribution Guidelines +## Contribution Guidelines - **To add a helper script:** Submit a pull request. Please use `#!/usr/bin/env interpreter` instead of a direct path to the interpreter, this makes it easier for people to use more recent versions when the ones packaged with their OS (macOS and CentOS, I'm looking at you) are stale. - **To remove a script:** All of the scripts here were either taken from blog posts or had an Open Source license. That said, if you wrote something included here and want it removed, either open an issue to discuss the removal or submit a pull request. diff --git a/PULL_REQUEST_TEMPLATE.md b/PULL_REQUEST_TEMPLATE.md index f0ed654ac..15dfcbbad 100644 --- a/PULL_REQUEST_TEMPLATE.md +++ b/PULL_REQUEST_TEMPLATE.md @@ -1,19 +1,23 @@ -## Description +# Description + -## Screenshots (if appropriate): +# Type of changes -## Type of changes + - [ ] A helper script - [ ] A link to an external resource like a blog post -## Checklist: +# Checklist: + + - [ ] All new and existing tests pass. -- [ ] Any scripts added use `#!/usr/bin/env interpreter` instead of potentially platform-specific direct paths (`#!/bin/sh` is an ok exception) +- [ ] Any scripts added use `#!/usr/bin/env interpreter` instead of potentially platform-specific direct paths (`#!/bin/sh` is an ok exception)\ +- [ ] Scripts are marked executable - [ ] I have confirmed that the link(s) in my PR are valid. - [ ] I have read the **CONTRIBUTING** document. diff --git a/bin/git-change-author b/bin/git-change-author index f7d6bed65..8c8cc5578 100755 --- a/bin/git-change-author +++ b/bin/git-change-author @@ -1,9 +1,9 @@ -#!/bin/sh +#!/bin/bash # Author: Michael Demmer https://github.com/demmer # License: MIT # Original source: https://github.com/jut-io/git-scripts/blob/master/bin/git-change-author -prog=`basename $0` +prog=$(basename "$0") force= if [ "$1" == "-f" ] ; then @@ -28,6 +28,7 @@ export old_email export new_author export new_email +# shellcheck disable=SC2016,SC2048,SC2086 git filter-branch $force --env-filter ' an="$GIT_AUTHOR_NAME" am="$GIT_AUTHOR_EMAIL" diff --git a/bin/git-copy-branch-name b/bin/git-copy-branch-name index 36329770e..35aa66779 100755 --- a/bin/git-copy-branch-name +++ b/bin/git-copy-branch-name @@ -1,10 +1,10 @@ -#!/bin/sh +#!/bin/bash # # Copy the current branch name to the clipboard. branch=$(git rev-parse --abbrev-ref HEAD) -echo $branch +echo "$branch" if [[ "$(uname -s)" = "Darwin" ]]; then - echo $branch | tr -d '\n' | tr -d ' ' | pbcopy + echo "$branch" | tr -d '\n' | tr -d ' ' | pbcopy fi diff --git a/bin/git-cut-branch b/bin/git-cut-branch index 815831e31..77609bef3 100755 --- a/bin/git-cut-branch +++ b/bin/git-cut-branch @@ -10,6 +10,7 @@ set -e # bail out with message to stderr and exit status 1 die() { + # shellcheck disable=SC2086 echo "$(basename $0):" "$@" 1>&2 exit 1 } @@ -20,6 +21,7 @@ shortsha() { } # show usage +# shellcheck disable=SC2166 [ -z "$1" -o "$1" = "--help" ] && { grep '^#/' "$0" |cut -c4- exit 2 @@ -44,6 +46,7 @@ remote=$(git config --get "branch.$current.remote" || true) merge=$(git config --get "branch.$current.merge" | sed 's@refs/heads/@@') # build up a sane / name +# shellcheck disable=SC2166 if [ -n "$remote" -a -n "$merge" ] then tracking="$remote/$merge" elif [ -n "$merge" ] @@ -63,5 +66,7 @@ git reset -q --hard "$tracking" git checkout -q "$branch" git branch --set-upstream "$branch" "$tracking" git reset -q --hard "$sha" +# shellcheck disable=SC2086,SC2046 echo "[$(shortsha "$sha")...$(shortsha $(git rev-parse $tracking))] $current" +# shellcheck disable=SC2046 echo "[0000000...$(shortsha $(git rev-parse HEAD))] $branch" diff --git a/bin/git-divergence b/bin/git-divergence index e4118eab9..60e21effa 100755 --- a/bin/git-divergence +++ b/bin/git-divergence @@ -6,6 +6,7 @@ set -e ( function branch() { + # shellcheck disable=SC2063 git branch 2>/dev/null | grep -e '^*' | tr -d '\* ' } @@ -13,7 +14,7 @@ set -e ref=$1 ( set +e - git show-ref $ref > /dev/null + git show-ref "$ref" > /dev/null if [[ $? == 1 ]]; then echo "$0: bad ref: $ref" exit 1 @@ -22,9 +23,10 @@ set -e } function show_rev() { - rev=$1 - git log -1 $rev --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit --date=relative + rev="$1" + git log -1 "$rev" --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit --date=relative echo + # shellcheck disable=SC2086 git diff $rev^..$rev | diffstat echo } @@ -33,29 +35,31 @@ set -e LOCAL=$1 REMOTE=$2 elif [[ $# == 1 ]]; then - LOCAL=`branch` + LOCAL=$(branch) REMOTE=$1 else - LOCAL=`branch` + LOCAL=$(branch) REMOTE=origin/$LOCAL fi - ensure_valid_ref $LOCAL - ensure_valid_ref $REMOTE + ensure_valid_ref "$LOCAL" + ensure_valid_ref "$REMOTE" echo "changes from local ${LOCAL} to remote ${REMOTE}:" echo echo incoming: echo - for rev in `git rev-list $LOCAL..$REMOTE`; do - show_rev $rev + # shellcheck disable=SC2086 + for rev in $(git rev-list $LOCAL..$REMOTE); do + show_rev "$rev" done echo echo outgoing: echo - for rev in `git rev-list $REMOTE..$LOCAL`; do - show_rev $rev + # shellcheck disable=SC2086 + for rev in $(git rev-list $REMOTE..$LOCAL); do + show_rev "$rev" done ) | less -r diff --git a/bin/git-github-open b/bin/git-github-open index 80d416701..a49fdaf93 100755 --- a/bin/git-github-open +++ b/bin/git-github-open @@ -14,6 +14,7 @@ ## Open current file in vim on line 20: ## :!github-open % 20 +# shellcheck disable=SC2002,SC2086 set -e FILE="$1" @@ -34,13 +35,14 @@ die() { # figure out relative path to the file from the root # of the work tree path="$(basename $FILE)" -cd $(dirname $FILE) +cd "$(dirname $FILE)" while test ! -d .git ; do test "$(pwd)" = / && { echo "error: git repository not found" 1>&2 exit 1 } + # shellcheck disable=SC2046 path="$(basename $(pwd))/$path" cd .. done @@ -81,4 +83,4 @@ url="http://github.com/$repo/blob/$branch/$path" # throw the line number on there if specified test -n "$LINE" && url="$url#L$LINE" -open "$url" \ No newline at end of file +open "$url" diff --git a/bin/git-incoming-commits b/bin/git-incoming-commits index 4912f8a81..93d8f8675 100755 --- a/bin/git-incoming-commits +++ b/bin/git-incoming-commits @@ -12,13 +12,14 @@ username="$1" if [ -n "$2" ] ; then repo="$2" else + # shellcheck disable=SC2046 repo=$(basename $(pwd)) fi command="git remote add $username git://github.com/$username/$repo.git" -echo $command +echo "$command" $command command="git fetch $username" -echo $command +echo "$command" $command diff --git a/bin/git-move-commits b/bin/git-move-commits index a59198e8e..1e6bd9996 100755 --- a/bin/git-move-commits +++ b/bin/git-move-commits @@ -6,9 +6,11 @@ # moves the last n commits to correct-branch # if correct-branch doesn't exist, it creates it # if correct-branch does exist, it merges the commits +# shellcheck disable=SC2046,SC2143,SC2006,SC2086,SC2063 + set -e -if [ $1 ] +if [ "$1" ] then if [ ! $(echo "$1" | grep -E "^[0-9]+$") ] then @@ -17,7 +19,7 @@ then exit 1; else # The count is 0 based, so to move the last 1 commit, we need HEAD~0 - NUM_COMMITS=$1 + NUM_COMMITS="$1" ((NUM_COMMITS--)) echo "num commits $NUM_COMMITS" fi diff --git a/bin/git-neck b/bin/git-neck index e8ad87d9c..d2bb94351 100755 --- a/bin/git-neck +++ b/bin/git-neck @@ -7,8 +7,11 @@ COMMIT=$(git rev-parse --no-flags --default HEAD "$@") # skip first elements of trail -TORSO=$(git trail $R $COMMIT | cut -d' ' -f2 | uniq | sed -n 2p) +TORSO=$(git trail "$R" "$COMMIT" | cut -d' ' -f2 | uniq | sed -n 2p) # fall back to initial commit on empty trail +# shellcheck disable=SC2046,SC2086 : ${TORSO:=$(git rev-list --max-parents=0 HEAD)} + +# shellcheck disable=SC2046,SC2086 git log --oneline $(git rev-parse --no-revs "$@") $COMMIT...$TORSO diff --git a/bin/git-publish b/bin/git-publish index 88486cd75..9f0ba96ff 100755 --- a/bin/git-publish +++ b/bin/git-publish @@ -1,12 +1,13 @@ #!/usr/bin/env bash # # https://github.com/cofi/dotfiles/blob/master/bin +# shellcheck disable=SC2063 remote=$1 current_branch="$(git branch | grep '^*' | sed s/\*\ //)" branch=${2:-$current_branch} -if [ -z $remote ]; then +if [ -z "$remote" ]; then echo "need at least remote to publish to" echo "usage: git publish remote [remote-branch]" exit 1 @@ -17,6 +18,6 @@ if [ -d ".git" ] && [ ! -d ".git/refs/remotes/$remote" ]; then exit 1 fi -git push $remote $branch && \ - git config branch.$current_branch.remote $remote && \ - git config branch.$current_branch.merge $branch +git push "$remote" "$branch" && \ + git config "branch.$current_branch.remote" "$remote" && \ + git config "branch.$current_branch.merge" "$branch" diff --git a/bin/git-unpushed-stat b/bin/git-unpushed-stat index b6ae0bb55..8e76c56a1 100755 --- a/bin/git-unpushed-stat +++ b/bin/git-unpushed-stat @@ -1,7 +1,7 @@ #!/bin/sh # # Show the diffstat of everything you haven't pushed yet. - +# shellcheck disable=SC2086 branch=$(git rev-parse --abbrev-ref HEAD) count=$(git rev-list --count HEAD origin/$branch...HEAD) @@ -13,4 +13,4 @@ else fi git diff --stat origin/$branch..HEAD -echo " $count commit$s total" \ No newline at end of file +echo " $count commit$s total" diff --git a/bin/git-winner b/bin/git-winner index 8211fd708..e1062d703 100755 --- a/bin/git-winner +++ b/bin/git-winner @@ -72,7 +72,7 @@ if [ "$HIGHEST_COMMIT_COUNT" -gt 0 ]; then echo "$HIGHEST_COMMIT_LINES_PLAYER wins in number of lines commited with $HIGHEST_COMMIT_LINES lines!" if [ "$HIGHEST_COMMIT_COUNT_PLAYER" = "$HIGHEST_COMMIT_LINES_PLAYER" ]; then - FIRST_NAME=$(echo $HIGHEST_COMMIT_COUNT_PLAYER | awk '{ print $1 }') + FIRST_NAME=$(echo "$HIGHEST_COMMIT_COUNT_PLAYER" | awk '{ print $1 }') echo "" echo "$FIRST_NAME is the overall winner!!"