1 #!/bin/sh |
|
2 |
|
3 cat > $HGRCPATH <<EOF |
|
4 [diff] |
|
5 git = True |
|
6 EOF |
|
7 |
|
8 cat > switch-eol.py <<EOF |
|
9 import sys |
|
10 |
|
11 try: |
|
12 import os, msvcrt |
|
13 msvcrt.setmode(sys.stdin.fileno(), os.O_BINARY) |
|
14 msvcrt.setmode(sys.stdout.fileno(), os.O_BINARY) |
|
15 except ImportError: |
|
16 pass |
|
17 |
|
18 (old, new) = sys.argv[1] == 'LF' and ('\n', '\r\n') or ('\r\n', '\n') |
|
19 print "%% switching encoding from %r to %r" % (old, new) |
|
20 for path in sys.argv[2:]: |
|
21 data = file(path, 'rb').read() |
|
22 data = data.replace(old, new) |
|
23 file(path, 'wb').write(data) |
|
24 EOF |
|
25 |
|
26 seteol () { |
|
27 if [ $1 = "LF" ]; then |
|
28 EOL='\n' |
|
29 else |
|
30 EOL='\r\n' |
|
31 fi |
|
32 } |
|
33 |
|
34 makerepo () { |
|
35 seteol $1 |
|
36 echo "% setup $1 repository" |
|
37 hg init repo |
|
38 cd repo |
|
39 |
|
40 cat > .hgeol <<EOF |
|
41 [repository] |
|
42 native = $1 |
|
43 |
|
44 [patterns] |
|
45 mixed.txt = BIN |
|
46 **.txt = native |
|
47 EOF |
|
48 |
|
49 printf "first${EOL}second${EOL}third${EOL}" > a.txt |
|
50 hg commit --addremove -m 'checkin' |
|
51 echo |
|
52 cd .. |
|
53 } |
|
54 |
|
55 dotest () { |
|
56 seteol $1 |
|
57 echo "% hg clone repo repo-$1" |
|
58 hg clone --noupdate repo repo-$1 |
|
59 cd repo-$1 |
|
60 |
|
61 cat > .hg/hgrc <<EOF |
|
62 [extensions] |
|
63 eol = |
|
64 |
|
65 [eol] |
|
66 native = $1 |
|
67 EOF |
|
68 |
|
69 hg update |
|
70 echo '% printrepr.py a.txt' |
|
71 python $TESTDIR/printrepr.py < a.txt |
|
72 echo '% hg cat a.txt' |
|
73 hg cat a.txt | python $TESTDIR/printrepr.py |
|
74 |
|
75 printf "fourth${EOL}" >> a.txt |
|
76 echo '% printrepr.py a.txt' |
|
77 python $TESTDIR/printrepr.py < a.txt |
|
78 hg diff | python $TESTDIR/printrepr.py |
|
79 |
|
80 python ../switch-eol.py $1 a.txt |
|
81 echo '% hg diff only reports a single changed line:' |
|
82 hg diff | python $TESTDIR/printrepr.py |
|
83 |
|
84 echo "% reverting back to $1 format" |
|
85 hg revert a.txt |
|
86 python $TESTDIR/printrepr.py < a.txt |
|
87 |
|
88 printf "first\r\nsecond\n" > mixed.txt |
|
89 hg add mixed.txt |
|
90 echo "% hg commit of inconsistent .txt file marked as binary (should work)" |
|
91 hg commit -m 'binary file' |
|
92 |
|
93 echo "% hg commit of inconsistent .txt file marked as native (should fail)" |
|
94 printf "first\nsecond\r\nthird\nfourth\r\n" > a.txt |
|
95 hg commit -m 'inconsistent file' |
|
96 |
|
97 echo "% hg commit --config eol.only-consistent=False (should work)" |
|
98 hg commit --config eol.only-consistent=False -m 'inconsistent file' |
|
99 |
|
100 echo "% hg commit of binary .txt file marked as native (binary files always okay)" |
|
101 printf "first${EOL}\0${EOL}third${EOL}" > a.txt |
|
102 hg commit -m 'binary file' |
|
103 |
|
104 cd .. |
|
105 rm -r repo-$1 |
|
106 } |
|
107 |
|
108 makerepo LF |
|
109 dotest LF |
|
110 dotest CRLF |
|
111 rm -r repo |
|
112 |
|
113 makerepo CRLF |
|
114 dotest LF |
|
115 dotest CRLF |
|
116 rm -r repo |
|
117 |
|
118 |
|
119 makemixedrepo () { |
|
120 echo |
|
121 echo "# setup $1 repository" |
|
122 hg init mixed |
|
123 cd mixed |
|
124 printf "foo\r\nbar\r\nbaz\r\n" > win.txt |
|
125 printf "foo\nbar\nbaz\n" > unix.txt |
|
126 #printf "foo\r\nbar\nbaz\r\n" > mixed.txt |
|
127 |
|
128 hg commit --addremove -m 'created mixed files' |
|
129 |
|
130 echo "# setting repository-native EOLs to $1" |
|
131 cat > .hgeol <<EOF |
|
132 [repository] |
|
133 native = $1 |
|
134 |
|
135 [patterns] |
|
136 **.txt = native |
|
137 EOF |
|
138 hg commit --addremove -m 'added .hgeol' |
|
139 cd .. |
|
140 } |
|
141 |
|
142 testmixed () { |
|
143 echo |
|
144 echo "% hg clone mixed mixed-$1" |
|
145 hg clone mixed mixed-$1 |
|
146 cd mixed-$1 |
|
147 |
|
148 echo '% hg status (eol extension not yet activated)' |
|
149 hg status |
|
150 |
|
151 cat > .hg/hgrc <<EOF |
|
152 [extensions] |
|
153 eol = |
|
154 |
|
155 [eol] |
|
156 native = $1 |
|
157 EOF |
|
158 |
|
159 echo '% hg status (eol activated)' |
|
160 hg status |
|
161 echo '% hg commit' |
|
162 hg commit -m 'synchronized EOLs' |
|
163 |
|
164 echo '% hg status' |
|
165 hg status |
|
166 |
|
167 cd .. |
|
168 rm -r mixed-$1 |
|
169 } |
|
170 |
|
171 makemixedrepo LF |
|
172 testmixed LF |
|
173 testmixed CRLF |
|
174 rm -r mixed |
|
175 |
|
176 makemixedrepo CRLF |
|
177 testmixed LF |
|
178 testmixed CRLF |
|
179 rm -r mixed |
|
180 |
|