From c4d1cd810d79007a7387beb1df93fa8ab820e1cd Mon Sep 17 00:00:00 2001 From: Henryk Iwaniuk Date: Mon, 30 Jan 2017 15:42:41 +0100 Subject: [PATCH 1/2] added option to only show local commits --- git-recall | 34 ++++++++++++++++++++++++++++++---- 1 file changed, 30 insertions(+), 4 deletions(-) diff --git a/git-recall b/git-recall index 1daaac9..ceb6b0d 100644 --- a/git-recall +++ b/git-recall @@ -10,6 +10,7 @@ usage() { -a, --author Author name. -f, --fetch fetch commits. -h, --help This message. + -l, --local Only show commits that have not yet been pushed to the remote branch. -- End of options. EOF } @@ -23,6 +24,8 @@ GIT_FORMAT="" GIT_LOG="" COMMITS="" VERSION="1.1.1" +TEMPLATE="default" +CURRENT_BRANCH="" # Are we in a git repo? if [[ ! -d ".git" ]]; then @@ -48,6 +51,9 @@ while [[ "$1" =~ ^- && ! "$1" == "--" ]]; do -f | --fetch ) FETCH=true ;; + -l | --local ) + TEMPLATE="local" + ;; -h | --help ) usage exit @@ -113,10 +119,30 @@ fi # Log template. GIT_FORMAT="%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset" -# Log command. -GIT_LOG="git log --pretty=format:'${GIT_FORMAT}' - --author \"$AUTHOR\" - --since \"$SINCE\" --abbrev-commit" +# Get currently tracked branch +function get_current_branch() { + if ! CURRENT_BRANCH=$(git rev-parse --abbrev-ref HEAD); then + echo "abort" 1>&2 + exit 1 + fi +} + +# Log command templates +function set_log_command() { + if [ "$TEMPLATE" == "local" ]; then + get_current_branch + GIT_LOG="git log --pretty=format:'${GIT_FORMAT}' + --abbrev-commit + origin/${CURRENT_BRANCH}..HEAD + " + else + GIT_LOG="git log --pretty=format:'${GIT_FORMAT}' + --author \"$AUTHOR\" + --since \"$SINCE\" --abbrev-commit" + fi +} + +set_log_command # Change temporary the IFS to store GIT_LOG's output into an array. IFS=$'\n' From 6b71d1249e985b63dadd03898f8a9cadf39296af Mon Sep 17 00:00:00 2001 From: Henryk Iwaniuk Date: Tue, 31 Jan 2017 16:23:55 +0100 Subject: [PATCH 2/2] Update documentation added documentation for the new option. --- README.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/README.md b/README.md index 74095d1..29775fd 100644 --- a/README.md +++ b/README.md @@ -16,6 +16,7 @@ check what you or other contributors in your team did. It doesn't aim to be a re ```sh $ git recall [-a ] [-d ] + [-l] [-f] [-h] ``` @@ -24,6 +25,7 @@ $ git recall [-a ] - `-a` - Restrict search for a specific user (use -a "all" for all users) - `-d` - Display commits for the last n days +- `-l` - show commits that have not been pushed to the remote branch. - `-f` - Fetch the latest changes - `-h` - Show help screen @@ -53,6 +55,9 @@ $ git recall -d 5 -a "Doge" $ git recall -d 5 -a "all" # The command will show commits of all contributors from 5 days ago. + +$ git recall -l +# The command will show commits that are present on the local branch, but have not yet been pushed to the remote. ```