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 git rev-list refs/remotes/git-svn >actual &&
43 test_line_count = 6 actual
44 )
45'
46
47test_expect_success 'authors-prog ran correctly' '
48 (
49 cd x &&
50 git rev-list -1 --pretty=raw refs/remotes/git-svn~1 >actual &&
51 grep "^author ee-foo <ee-foo@example\.com> " actual &&
52 git rev-list -1 --pretty=raw refs/remotes/git-svn~2 >actual &&
53 grep "^author dd <dd@sub\.example\.com> " actual &&
54 git rev-list -1 --pretty=raw refs/remotes/git-svn~3 >actual &&
55 grep "^author cc <cc@sub\.example\.com> " actual &&
56 git rev-list -1 --pretty=raw refs/remotes/git-svn~4 >actual &&
57 grep "^author bb <bb@example\.com> " actual &&
58 git rev-list -1 --pretty=raw refs/remotes/git-svn~5 >actual &&
59 grep "^author aa <aa@example\.com> " actual
60 )
61'
62
63test_expect_success 'authors-file overrode authors-prog' '
64 (
65 cd x &&
66 git rev-list -1 --pretty=raw refs/remotes/git-svn >actual &&
67 grep "^author FFFFFFF FFFFFFF <fFf@other\.example\.com> " actual
68 )
69'
70
71git --git-dir=x/.git config --unset svn.authorsfile
72git --git-dir=x/.git config --unset svn.authorsprog
73
74test_expect_success 'authors-prog imported user without email' '
75 svn mkdir -m gg --username gg-hermit "$svnrepo"/gg &&
76 (
77 cd x &&
78 git svn fetch --authors-prog=../svn-authors-prog &&
79 git rev-list -1 --pretty=raw refs/remotes/git-svn | \
80 grep "^author gg <> "
81 )
82'
83
84test_expect_success 'imported without authors-prog and authors-file' '
85 svn mkdir -m hh --username hh "$svnrepo"/hh &&
86 (
87 uuid=$(svn info "$svnrepo" |
88 sed -n "s/^Repository UUID: //p") &&
89 cd x &&
90 git svn fetch &&
91 git rev-list -1 --pretty=raw refs/remotes/git-svn | \
92 grep "^author hh <hh@$uuid> "
93 )
94'
95
96test_expect_success 'authors-prog handled special characters in username' '
97 svn mkdir -m bad --username "xyz; touch evil" "$svnrepo"/bad &&
98 (
99 cd x &&
100 git svn --authors-prog=../svn-authors-prog fetch &&
101 git rev-list -1 --pretty=raw refs/remotes/git-svn >actual &&
102 grep "^author xyz; touch evil <xyz; touch evil@example\.com> " actual &&
103 ! test -f evil
104 )
105'
106
107test_done