From 4cbe353eb102be1d2cf9ac4eaac67c0e43607793 Mon Sep 17 00:00:00 2001 From: Jonathan Lai Date: Sun, 22 Jan 2017 00:41:08 -0800 Subject: [PATCH 1/2] Add check to see if the current directory is a git repo --- git-redate | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/git-redate b/git-redate index 5040aa6..1d56730 100755 --- a/git-redate +++ b/git-redate @@ -1,5 +1,16 @@ #!/bin/bash +is_git_repo() { + git rev-parse --show-toplevel > /dev/null 2>&1 + result=$? + if test $result != 0; then + >&2 echo 'Not a git repo!' + exit $result + fi +} + +is_git_repo + while [[ $# -gt 1 ]] do key="$1" From 30c6f2639931016a39f40c994a026405b28eee2e Mon Sep 17 00:00:00 2001 From: Jonathan Lai Date: Sun, 22 Jan 2017 01:06:24 -0800 Subject: [PATCH 2/2] Make indentation consistent --- git-redate | 46 +++++++++++++++++++++++----------------------- 1 file changed, 23 insertions(+), 23 deletions(-) diff --git a/git-redate b/git-redate index 1d56730..9e175f3 100755 --- a/git-redate +++ b/git-redate @@ -1,11 +1,11 @@ #!/bin/bash is_git_repo() { - git rev-parse --show-toplevel > /dev/null 2>&1 - result=$? - if test $result != 0; then - >&2 echo 'Not a git repo!' - exit $result + git rev-parse --show-toplevel > /dev/null 2>&1 + result=$? + if test $result != 0; then + >&2 echo 'Not a git repo!' + exit $result fi } @@ -16,13 +16,13 @@ do key="$1" case $key in - -c| --commits) - COMMITS="$2" - shift - ;; - *) - # unknown option - ;; + -c| --commits) + COMMITS="$2" + shift + ;; + *) + # unknown option + ;; esac shift done @@ -46,17 +46,17 @@ ${VISUAL:-${EDITOR:-vi}} $tmpfile ENVFILTER="" while read commit; do - IFS="|" read date hash message <<< "$commit" - DATE_NO_SPACE="$(echo "${date}" | tr -d '[[:space:]]')" - COMMIT_ENV=$(cat <<-END - if [ \$GIT_COMMIT = $hash ]; - then - export GIT_AUTHOR_DATE="$DATE_NO_SPACE" - export GIT_COMMITTER_DATE="$DATE_NO_SPACE"; - fi; - END - ) - ENVFILTER="$ENVFILTER$COMMIT_ENV" + IFS="|" read date hash message <<< "$commit" + DATE_NO_SPACE="$(echo "${date}" | tr -d '[[:space:]]')" + COMMIT_ENV=$(cat <<-END + if [ \$GIT_COMMIT = $hash ]; + then + export GIT_AUTHOR_DATE="$DATE_NO_SPACE" + export GIT_COMMITTER_DATE="$DATE_NO_SPACE"; + fi; + END + ) + ENVFILTER="$ENVFILTER$COMMIT_ENV" done < $tmpfile git filter-branch -f --env-filter "$ENVFILTER" >/dev/null