From: "\"Peter Valdemar Mørch (Lists)\"" <4ux6as402@sneakemail.com>
To: git@vger.kernel.org
Subject: Re: How to fix (and find) many git-* --check errors?
Date: Fri, 08 Aug 2008 16:57:25 +0200 [thread overview]
Message-ID: <489C5ED5.2060501@sneakemail.com> (raw)
In-Reply-To: <489C40BC.8000008@sneakemail.com>
Thanks to hints from both Jeff King and Björn Stenbrink I got it
working. Here is my script, if anybody is interested.
It handles both fixing whitespace in current workspace diffs:
$ git-fix-whitespace file
(requires existing diffs)
and fixing all whitespace problems in a file:
$ git-fix-whitespace -f file
(asserts no existing diffs)
Now all I need to do is grock how to fix stuff already in the index, but
I'll leave that for another day...
Peter
-----------------
#!/bin/bash
# Take a -f option to fix all whitespace problems in entire files
# completely. Otherwise only fix current diffs.
# Option handling
while getopts fh? o
do
case "$o" in
f) fixEntireFile=1;;
[h?]) echo >&2 "Usage: $0 [-f] file ..."
echo >&2 "-f: Fix the entire file"
echo >&2 " Otherwise only fix current diffs"
exit 1;;
esac
done
shift $(($OPTIND-1))
# A constant for a rev that is empty
EMPTY_TREE_SHA1=4b825dc642cb6eb9a060e54bf8d69288fbee4904
# Check to see we're on a clean HEAD just to be sure.
# (Not sure this is necessary, but just in case.)
git --no-pager diff --exit-code HEAD -- "$@" > /dev/null
if [ $? = 0 ] ; then
# There is no current diff
if [ "$fixEntireFile" != "" ] ; then
# Good, there is no diff, and we've been asked to fix
# the entire file
# Remove all files - the -f for rm is just needed if
# $@ happens to contain only untracked files
git-ls-tree -z -r --name-status HEAD "$@" | \
xargs --null rm -f
# Re-create the files - but with whitespace fixed
git diff $EMPTY_TREE_SHA1 HEAD -- "$@" | \
git-apply --whitespace=fix
else
echo >&2 '*Error*: there no diff with HEAD'
exit 1
fi
else
# There is a current diff
if [ "$fixEntireFile" = "" ] ; then
# Good, there is a current diff, that we need to fix
TEMP_FILE=$(tempfile)
git diff -- "$@" > $TEMP_FILE
git checkout HEAD -- "$@"
git apply --whitespace=fix $TEMP_FILE
rm $TEMP_FILE
else
echo >&2 '*Error*: there is diff with HEAD'
exit 1
fi
fi
next prev parent reply other threads:[~2008-08-08 14:58 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-08-08 12:49 How to fix (and find) many git-* --check errors? "Peter Valdemar Mørch (Lists)"
2008-08-08 13:23 ` Jeff King
2008-08-08 13:28 ` Björn Steinbrink
2008-08-08 14:57 ` "Peter Valdemar Mørch (Lists)" [this message]
2008-08-08 19:27 ` Junio C Hamano
2008-08-09 7:28 ` "Peter Valdemar Mørch (Lists)"
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=489C5ED5.2060501@sneakemail.com \
--to=4ux6as402@sneakemail.com \
--cc=git@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.