1#!/bin/sh
2#
3# Copyright (c) 2009 Eric Wong, Mark Lodato
4#
5
6test_description='git svn authors prog tests'
7
8. ./lib-git-svn.sh
9
10write_script svn-authors-prog "$PERL_PATH" <<-\EOF
11 $_ = shift;
12 if (s/-hermit//) {
13 print "$_ <>\n";
14 } elsif (s/-sub$//) {
15 print "$_ <$_\@sub.example.com>\n";
16 } else {
17 print "$_ <$_\@example.com>\n";
18 }
19EOF
20
21test_expect_success 'svn-authors setup' '
22 cat >svn-authors <<-\EOF
23 ff = FFFFFFF FFFFFFF <fFf@other.example.com>
24 EOF
25'
26
27test_expect_success 'setup svnrepo' '
28 for i in aa bb cc-sub dd-sub ee-foo ff
29 do
30 svn mkdir -m $i --username $i "$svnrepo"/$i
31 done
32'
33
34test_expect_success 'import authors with prog and file' '
35 git svn clone --authors-prog=./svn-authors-prog \
36 --authors-file=svn-authors "$svnrepo" x
37'
38
39test_expect_success 'imported 6 revisions successfully' '
40 (
41 cd x
42 test "$(git rev-list refs/remotes/git-svn | wc -l)" -eq 6
43 )
44'
45
46test_expect_success 'authors-prog ran correctly' '
47 (
48 cd x
49 git rev-list -1 --pretty=raw refs/remotes/git-svn~1 | \
50 grep "^author ee-foo <ee-foo@example\.com> " &&
51 git rev-list -1 --pretty=raw refs/remotes/git-svn~2 | \
52 grep "^author dd <dd@sub\.example\.com> " &&
53 git rev-list -1 --pretty=raw refs/remotes/git-svn~3 | \
54 grep "^author cc <cc@sub\.example\.com> " &&
55 git rev-list -1 --pretty=raw refs/remotes/git-svn~4 | \
56 grep "^author bb <bb@example\.com> " &&
57 git rev-list -1 --pretty=raw refs/remotes/git-svn~5 | \
58 grep "^author aa <aa@example\.com> "
59 )
60'
61
62test_expect_success 'authors-file overrode authors-prog' '
63 (
64 cd x
65 git rev-list -1 --pretty=raw refs/remotes/git-svn | \
66 grep "^author FFFFFFF FFFFFFF <fFf@other\.example\.com> "
67 )
68'
69
70git --git-dir=x/.git config --unset svn.authorsfile
71git --git-dir=x/.git config --unset svn.authorsprog
72
73test_expect_success 'authors-prog imported user without email' '
74 svn mkdir -m gg --username gg-hermit "$svnrepo"/gg &&
75 (
76 cd x &&
77 git svn fetch --authors-prog=../svn-authors-prog &&
78 git rev-list -1 --pretty=raw refs/remotes/git-svn | \
79 grep "^author gg <> "
80 )
81'
82
83test_expect_success 'imported without authors-prog and authors-file' '
84 svn mkdir -m hh --username hh "$svnrepo"/hh &&
85 (
86 uuid=$(svn info "$svnrepo" |
87 sed -n "s/^Repository UUID: //p") &&
88 cd x &&
89 git svn fetch &&
90 git rev-list -1 --pretty=raw refs/remotes/git-svn | \
91 grep "^author hh <hh@$uuid> "
92 )
93'
94
95test_expect_success 'authors-prog handled special characters in username' '
96 svn mkdir -m bad --username "xyz; touch evil" "$svnrepo"/bad &&
97 (
98 cd x &&
99 git svn --authors-prog=../svn-authors-prog fetch &&
100 git rev-list -1 --pretty=raw refs/remotes/git-svn |
101 grep "^author xyz; touch evil <xyz; touch evil@example\.com> " &&
102 ! test -f evil
103 )
104'
105
106test_done