Skip to content

Commit 3429520

Browse files
committed
Add git-files and git-stats scripts
- Add `git-files` and `git-stats` scripts - Bugfix in `git-origin-head` script Signed-off-by: Joe Block <jpb@unixorn.net>
1 parent dfcde55 commit 3429520

File tree

4 files changed

+68
-1
lines changed

4 files changed

+68
-1
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ If you wrote one of these scripts and want it removed from this collection, plea
7979
| `git-divergence` | Gary Bernhardt's [dotfiles](https://github.com/garybernhardt/dotfiles/blob/master/bin/git-churn) | Shows differences between local branch and its tracking branch. |
8080
| `git-edit-conflicts` | Joe Block <jpb@unixorn.net> | Edit the files that are marked as conflicted during a merge/rebase in your `$EDITOR/$VISUAL`. |
8181
| `git-fetch-prs` | Pretty sure I saw this on slack, but can't recall which one | Get all Pull Request branches as local remote branches by refspec |
82+
| `git-files` | Jake Zimmerman's [blog](https://blog.jez.io/cli-code-review/) | List the files different between the current branch and `$REVIEW_BRANCH`, which if unset defaults to the repository's default branch |
8283
| `git-find-dirty` | Matthew McCullough's [scripts](https://github.com/matthewmccullough/scripts/) repository | |
8384
| `git-flush` | John Wiegley's [git-scripts](https://github.com/jwiegley/git-scripts) | Compact your reposistory by dropping all reflogs, stashes, and other cruft that may be bloating your pack files. |
8485
| `git-force-mtimes` | John Wiegley's [git-scripts](https://github.com/jwiegley/git-scripts) | Sets modification times of all files in the reprository their last change date based on `git`'s log. Useful to avoid too new dates after a checkout confusing `make` or `rake`. |
@@ -136,6 +137,7 @@ If you wrote one of these scripts and want it removed from this collection, plea
136137
| `git-shrink-repo` | Based on [gimbo/gimbo-git.zsh](https://github.com/gimbo/gimbo-git.zsh/blob/master/gimbo-git.zsh) | Shrinks your clone of a `git` repo. |
137138
| `git-sp` | A. Schwarz's [git-sp](https://github.com/Schwarzy1/git-sp) | "Simple push", single short command to commit, and push. Use `-a` flag to add all files to commit. |
138139
| `git-sr` | Noel Cower's [git-sr](https://gist.github.com/nilium/2829f6690ad888c25660c15ba3a7c59c) | Use `fzf` to switch to a different `git` ref. |
140+
| `git-stats` | Jake Zimmerman's [blog](https://blog.jez.io/cli-code-review/) | Displays stats for the files different between the current branch and `$REVIEW_BRANCH`, which if unset defaults to the repository's default branch |
139141
| `git-submodule-rm` | Greg V's [dotfiles](https://github.com/myfreeweb/dotfiles) & [Pascal Sommer](https://github.com/pascal-so/) | Allows you to remove a submodule easily with `git submodule-rm path/to/submodule`. |
140142
| `git-switch-branch` | Andrew Steele's [dotfiles](https://github.com/Andrew565/dotfiles) | Make it easier to switch to a branch by a substring of its name. More useful if you are good about deleting branches which have been merged upstream and if your branch names include unique identifiers like ticket/issue numbers or feature names. |
141143
| `git-tag-and-sign` | ? | Create and sign a new tag |

bin/git-files

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#!/usr/bin/env bash
2+
#
3+
# git files
4+
#
5+
# Based on https://blog.jez.io/cli-code-review/
6+
7+
8+
set -o pipefail
9+
if [[ -n "$DEBUG" ]]; then
10+
set -x
11+
fi
12+
13+
function debug() {
14+
if [[ -n "$DEBUG" ]]; then
15+
echo "$@"
16+
fi
17+
}
18+
19+
function fail() {
20+
printf '%s\n' "$1" >&2 ## Send message to stderr. Exclude >&2 if you don't want it that way.
21+
exit "${2-1}" ## Return a code specified by $2 or 1 by default.
22+
}
23+
24+
function has() {
25+
# Check if a command is in $PATH
26+
which "$@" > /dev/null 2>&1
27+
}
28+
29+
if [[ -z "$REVIEW_BASE" ]]; then
30+
REVIEW_BASE="$(git remote show origin | grep 'HEAD branch' | cut -d ' ' -f5)"
31+
fi
32+
33+
exec git diff --name-only "$(git merge-base HEAD "$REVIEW_BASE")"

bin/git-origin-head

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ function has() {
2525
which "$@" > /dev/null 2>&1
2626
}
2727

28-
trap cleanup EXIT
2928
if has git; then
3029
git remote show origin | grep 'HEAD branch' | cut -d ' ' -f5
3130
else

bin/git-stats

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#!/usr/bin/env bash
2+
#
3+
# git stats
4+
#
5+
# Based on https://blog.jez.io/cli-code-review/
6+
7+
8+
set -o pipefail
9+
if [[ -n "$DEBUG" ]]; then
10+
set -x
11+
fi
12+
13+
function debug() {
14+
if [[ -n "$DEBUG" ]]; then
15+
echo "$@"
16+
fi
17+
}
18+
19+
function fail() {
20+
printf '%s\n' "$1" >&2 ## Send message to stderr. Exclude >&2 if you don't want it that way.
21+
exit "${2-1}" ## Return a code specified by $2 or 1 by default.
22+
}
23+
24+
function has() {
25+
# Check if a command is in $PATH
26+
which "$@" > /dev/null 2>&1
27+
}
28+
29+
if [[ -z "$REVIEW_BASE" ]]; then
30+
REVIEW_BASE="$(git remote show origin | grep 'HEAD branch' | cut -d ' ' -f5)"
31+
fi
32+
33+
exec git diff --stat "$(git merge-base HEAD "$REVIEW_BASE")"

0 commit comments

Comments
 (0)