Created
September 12, 2012 10:28
-
-
Save scy/3705796 to your computer and use it in GitHub Desktop.
Un-expand $Id$ in a git-svn repository, with some special powers
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# The problem: | |
# | |
# You have a clean git-svn working copy and, for example, rsync the files from | |
# the production server into it in order to find out whether some files have | |
# been changed directly on the server, without committing. | |
# | |
# However, the files on the production server possibly have $Id$ expanded, and | |
# now you're seeing a _lot_ of changed files which contain no differences except | |
# for the $Id$ expansion. | |
# | |
# So you're using sed magic to replace expanded $Id$s by unexpanded ones, but | |
# now you find out that sed will ensure that files have a newline at EOF. Which | |
# is basically a good thing, but if your repository contains files without these | |
# newlines at EOF, sed will add the newlines and git will consider them changed. | |
# | |
# You _could_ "fix" these files and commit the EOF changes, but if you can't or | |
# don't want to, you can use this script. | |
# | |
# It will unexpand $Id$ (could be extended to unexpand other keywords as well) | |
# and then do a "git diff" on the file to check whether its only change is the | |
# trailing newline. If so, it will run a "git checkout" on it in order to reset | |
# it to the version in your repository. | |
git status -s | sed -n -e 's/^ M \(.*\)$/\1/p' | while read -r file; do | |
sed -i '' -e 's/\$Id: [^$]*\$/$Id$/g' "$file" && \ | |
[ "$(git diff -U0 "$file" | awk ' | |
NR == 6 { a = substr($0, 2); }; | |
NR == 7 { nonl = (substr($0, 1, 1) == "\\"); }; | |
NR == 8 { b = substr($0, 2); }; | |
END { if ((NR == 8) && (a == b) && nonl) { print "nonl"; } }; | |
')" = 'nonl' ] && echo "$file" | |
done | xargs git checkout |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment