Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 55 additions & 0 deletions .codeclimate.yml
Original file line number Diff line number Diff line change
@@ -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/**/*
4 changes: 2 additions & 2 deletions Contributing.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
14 changes: 9 additions & 5 deletions PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -1,19 +1,23 @@
<!--- Provide a general summary of your changes in the Title above -->

## Description
# Description

<!--- Describe your changes in detail -->

## Screenshots (if appropriate):
# Type of changes

## Type of changes
<!--- What types of changes does your submission introduce? Put an `x` in all the boxes that apply: -->

- [ ] A helper script
- [ ] A link to an external resource like a blog post

## Checklist:
# Checklist:

<!--- Go over all the following points, and put an `x` in all the boxes that apply. -->
<!--- If you're unsure about any of these, don't hesitate to ask. I'm happy to help! -->

- [ ] 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.
5 changes: 3 additions & 2 deletions bin/git-change-author
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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"
Expand Down
6 changes: 3 additions & 3 deletions bin/git-copy-branch-name
Original file line number Diff line number Diff line change
@@ -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
5 changes: 5 additions & 0 deletions bin/git-cut-branch
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -20,6 +21,7 @@ shortsha() {
}

# show usage
# shellcheck disable=SC2166
[ -z "$1" -o "$1" = "--help" ] && {
grep '^#/' "$0" |cut -c4-
exit 2
Expand All @@ -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 <remote>/<branch> name
# shellcheck disable=SC2166
if [ -n "$remote" -a -n "$merge" ]
then tracking="$remote/$merge"
elif [ -n "$merge" ]
Expand All @@ -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"
26 changes: 15 additions & 11 deletions bin/git-divergence
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@ set -e

(
function branch() {
# shellcheck disable=SC2063
git branch 2>/dev/null | grep -e '^*' | tr -d '\* '
}

function ensure_valid_ref() {
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
Expand All @@ -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
}
Expand All @@ -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
6 changes: 4 additions & 2 deletions bin/git-github-open
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
## Open current file in vim on line 20:
## :!github-open % 20

# shellcheck disable=SC2002,SC2086
set -e

FILE="$1"
Expand All @@ -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
Expand Down Expand Up @@ -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"
open "$url"
5 changes: 3 additions & 2 deletions bin/git-incoming-commits
Original file line number Diff line number Diff line change
Expand Up @@ -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
6 changes: 4 additions & 2 deletions bin/git-move-commits
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
5 changes: 4 additions & 1 deletion bin/git-neck
Original file line number Diff line number Diff line change
Expand Up @@ -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
9 changes: 5 additions & 4 deletions bin/git-publish
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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"
4 changes: 2 additions & 2 deletions bin/git-unpushed-stat
Original file line number Diff line number Diff line change
@@ -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)

Expand All @@ -13,4 +13,4 @@ else
fi

git diff --stat origin/$branch..HEAD
echo " $count commit$s total"
echo " $count commit$s total"
2 changes: 1 addition & 1 deletion bin/git-winner
Original file line number Diff line number Diff line change
Expand Up @@ -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!!"
Expand Down