Skip to content

Commit

Permalink
Merge pull request #5 from clagix/fixes-clagix
Browse files Browse the repository at this point in the history
Fix to support older git version
  • Loading branch information
EdmundMai authored Mar 21, 2017
2 parents daa1e48 + eea65d4 commit 73db119
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions git-redate
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,16 @@ tmpfile=$(mktemp gitblah-XXXX)
[ -f "$tmpfile" ] || die "could not get tmpfile=[$tmpfile]"
trap "rm -f $tmpfile" EXIT


datefmt=%cI
if [ "`git log -n1 --pretty=format:"$datefmt"`" == "$datefmt" ];
then
datefmt=%ci
fi

if [ -n "${COMMITS+set}" ];
then git log -n $COMMITS --pretty=format:"%cI | %H | %s" > $tmpfile;
else git log -n 5 --pretty=format:"%cI | %H | %s" > $tmpfile;
then git log -n $COMMITS --pretty=format:"$datefmt | %H | %s" > $tmpfile;
else git log -n 5 --pretty=format:"$datefmt | %H | %s" > $tmpfile;
fi

${VISUAL:-${EDITOR:-vi}} $tmpfile
Expand All @@ -47,19 +54,24 @@ ${VISUAL:-${EDITOR:-vi}} $tmpfile
ENVFILTER=""
while read commit; do
IFS="|" read date hash message <<< "$commit"
DATE_NO_SPACE="$(echo "${date}" | tr -d '[[:space:]]')"
if [ "$datefmt" == "%cI" ]
then
DATE_NO_SPACE="$(echo "${date}" | tr -d '[[:space:]]')"
else
DATE_NO_SPACE="$(echo "${date}")"
fi
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
END
)
ENVFILTER="$ENVFILTER$COMMIT_ENV"
done < $tmpfile

git filter-branch -f --env-filter "$ENVFILTER" >/dev/null
git filter-branch -f --env-filter "$ENVFILTER" HEAD~$COMMITS..HEAD >/dev/null
if [ $? = 0 ] ; then
echo "Git commit dates updated. Run 'git push -f BRANCH_NAME' to push your changes."
else
Expand Down

0 comments on commit 73db119

Please sign in to comment.