Skip to content

Commit

Permalink
Merge pull request #4 from agsdot/master
Browse files Browse the repository at this point in the history
Add check to see if the current directory is a git repo
  • Loading branch information
EdmundMai authored Feb 20, 2017
2 parents 2a5982b + 30c6f26 commit daa1e48
Showing 1 changed file with 29 additions and 18 deletions.
47 changes: 29 additions & 18 deletions git-redate
Original file line number Diff line number Diff line change
@@ -1,17 +1,28 @@
#!/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"

case $key in
-c| --commits)
COMMITS="$2"
shift
;;
*)
# unknown option
;;
-c| --commits)
COMMITS="$2"
shift
;;
*)
# unknown option
;;
esac
shift
done
Expand All @@ -35,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
Expand Down

0 comments on commit daa1e48

Please sign in to comment.