Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added option to only show local commits #17

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 <author name>]
[-d <days-ago>]
[-l]
[-f]
[-h]
```
Expand All @@ -24,6 +25,7 @@ $ git recall [-a <author name>]

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

Expand Down Expand Up @@ -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.
```


Expand Down
34 changes: 30 additions & 4 deletions git-recall
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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
Expand All @@ -48,6 +51,9 @@ while [[ "$1" =~ ^- && ! "$1" == "--" ]]; do
-f | --fetch )
FETCH=true
;;
-l | --local )
TEMPLATE="local"
;;
-h | --help )
usage
exit
Expand Down Expand Up @@ -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'
Expand Down