-
Notifications
You must be signed in to change notification settings - Fork 240
/
git-svn-diff
executable file
·71 lines (62 loc) · 2.33 KB
/
git-svn-diff
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#!/bin/sh
#
# git-svn-diff -- SVN-compatible diff against the tip of the tracking branch
#
# ChangeLog
#
# Originally by http://mojodna.net/2009/02/24/my-work-git-workflow.html
#
# - <unknown changes>
#
# aconway@[redacted]
# - handle diffs that introduce new files
#
# - Use readable POSIX $() instead backticsk
# - Add ChangeLog
# - Convert from bash to plain /bin/sh
# - Fit as much as possible in 80 columns
# - Make sed \/ quoting more readable using alternative separators
# - Remove EOL whitespaces.
# - 2011-12-27 Incorporate fixes by https://github.com/nfloyd
# from the Gist comment 2011-07-31 https://gist.github.com/946727
#
# <javabrett>
# - Retain space after leading --- and +++, add TAB before (revision 0)
# - Use \t instead of spaces before (revision $REV) and (working copy)
#
# <javabrett>
# - Added support for non-empty git-svn prefix, important now that the
# - default --prefix is "origin/" in Git 2.0+.
# Get the tracking branch (if we're on a branch)
TRACKING_BRANCH=$(git svn info | grep URL | sed -e 's,.*/branches/,,')
# If the tracking branch has 'URL' at the beginning, then the sed
# wasn't successful and we'll fall back to the svn-remote config
# option
case "$TRACKING_BRANCH" in
URL*)
TRACKING_BRANCH=$(git config --get svn-remote.svn.fetch |
sed -e 's,.*:refs/remotes/,,')
;;
*)
# GIT_SVN_PREFIX will be origin/ by-default in Git 2.0 or later, or ""
GIT_SVN_PREFIX=$(git config --get svn-remote.svn.branches | sed -e 's,.*:refs/remotes/\(.*\)\*$,\1,')
TRACKING_BRANCH=${GIT_SVN_PREFIX}${TRACKING_BRANCH}
;;
esac
# Get the highest revision number
REV=$(git svn info |
grep 'Last Changed Rev:' |
sed --regexp-extended 's/^.*: ([[:digit:]]*)/\1/')
# Then do the diff from the highest revision on the current branch and
# masssage into SVN format
git diff \
--no-prefix $(git rev-list --date-order --max-count=1 $TRACKING_BRANCH) \
"$@" |
sed -e "/--- \/dev\/null/{ N; s|^--- /dev/null\n+++ \(.*\)|--- \1\t(revision 0)\n+++ \1\t(revision 0)|;}" \
-e "s/^--- .*/&\t(revision $REV)/" \
-e "s/^+++ .*/&\t(working copy)/" \
-e "s/^diff --git [^[:space:]]*/Index:/" \
-e "s/^index.*/===================================================================/"
# End of file