summaryrefslogtreecommitdiff
path: root/tests/test-eol-hook.t
blob: 12716bc3832d39838cba18fee20034152e74d19b (plain)
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
Test the EOL hook

  $ hg init main
  $ cat > main/.hg/hgrc <<EOF
  > [hooks]
  > pretxnchangegroup = python:hgext.eol.hook
  > EOF
  $ hg clone main fork
  updating to branch default
  0 files updated, 0 files merged, 0 files removed, 0 files unresolved
  $ cd fork

Create repo
  $ cat > .hgeol <<EOF
  > [patterns]
  > mixed.txt = BIN
  > crlf.txt = CRLF
  > **.txt = native
  > EOF
  $ hg add .hgeol
  $ hg commit -m 'Commit .hgeol'

  $ printf "first\nsecond\nthird\n" > a.txt
  $ hg add a.txt
  $ hg commit -m 'LF a.txt'
  $ hg push ../main
  pushing to ../main
  searching for changes
  adding changesets
  adding manifests
  adding file changes
  added 2 changesets with 2 changes to 2 files

  $ printf "first\r\nsecond\r\nthird\n" > a.txt
  $ hg commit -m 'CRLF a.txt'
  $ hg push ../main
  pushing to ../main
  searching for changes
  adding changesets
  adding manifests
  adding file changes
  added 1 changesets with 1 changes to 1 files
  error: pretxnchangegroup hook failed: end-of-line check failed:
    a.txt in a8ee6548cd86 should not have CRLF line endings
  transaction abort!
  rollback completed
  abort: end-of-line check failed:
    a.txt in a8ee6548cd86 should not have CRLF line endings
  [255]

  $ printf "first\nsecond\nthird\n" > a.txt
  $ hg commit -m 'LF a.txt (fixed)'
  $ hg push ../main
  pushing to ../main
  searching for changes
  adding changesets
  adding manifests
  adding file changes
  added 2 changesets with 2 changes to 1 files

  $ printf "first\nsecond\nthird\n" > crlf.txt
  $ hg add crlf.txt
  $ hg commit -m 'LF crlf.txt'
  $ hg push ../main
  pushing to ../main
  searching for changes
  adding changesets
  adding manifests
  adding file changes
  added 1 changesets with 1 changes to 1 files
  error: pretxnchangegroup hook failed: end-of-line check failed:
    crlf.txt in 004ba2132725 should not have LF line endings
  transaction abort!
  rollback completed
  abort: end-of-line check failed:
    crlf.txt in 004ba2132725 should not have LF line endings
  [255]

  $ printf "first\r\nsecond\r\nthird\r\n" > crlf.txt
  $ hg commit -m 'CRLF crlf.txt (fixed)'
  $ hg push ../main
  pushing to ../main
  searching for changes
  adding changesets
  adding manifests
  adding file changes
  added 2 changesets with 2 changes to 1 files

  $ printf "first\r\nsecond" > b.txt
  $ hg add b.txt
  $ hg commit -m 'CRLF b.txt'
  $ hg push ../main
  pushing to ../main
  searching for changes
  adding changesets
  adding manifests
  adding file changes
  added 1 changesets with 1 changes to 1 files
  error: pretxnchangegroup hook failed: end-of-line check failed:
    b.txt in fbcf9b1025f5 should not have CRLF line endings
  transaction abort!
  rollback completed
  abort: end-of-line check failed:
    b.txt in fbcf9b1025f5 should not have CRLF line endings
  [255]

  $ hg up -r -2
  0 files updated, 0 files merged, 1 files removed, 0 files unresolved
  $ printf "some\nother\nfile" > c.txt
  $ hg add c.txt
  $ hg commit -m "LF c.txt, b.txt doesn't exist here"
  created new head
  $ hg push -f ../main
  pushing to ../main
  searching for changes
  adding changesets
  adding manifests
  adding file changes
  added 2 changesets with 2 changes to 2 files (+1 heads)
  error: pretxnchangegroup hook failed: end-of-line check failed:
    b.txt in fbcf9b1025f5 should not have CRLF line endings
  transaction abort!
  rollback completed
  abort: end-of-line check failed:
    b.txt in fbcf9b1025f5 should not have CRLF line endings
  [255]

Test checkheadshook alias

  $ cat > ../main/.hg/hgrc <<EOF
  > [hooks]
  > pretxnchangegroup = python:hgext.eol.checkheadshook
  > EOF
  $ hg push -f ../main
  pushing to ../main
  searching for changes
  adding changesets
  adding manifests
  adding file changes
  added 2 changesets with 2 changes to 2 files (+1 heads)
  error: pretxnchangegroup hook failed: end-of-line check failed:
    b.txt in fbcf9b1025f5 should not have CRLF line endings
  transaction abort!
  rollback completed
  abort: end-of-line check failed:
    b.txt in fbcf9b1025f5 should not have CRLF line endings
  [255]

We can fix the head and push again

  $ hg up 6
  1 files updated, 0 files merged, 1 files removed, 0 files unresolved
  $ printf "first\nsecond" > b.txt
  $ hg ci -m "remove CRLF from b.txt"
  $ hg push -f ../main
  pushing to ../main
  searching for changes
  adding changesets
  adding manifests
  adding file changes
  added 3 changesets with 3 changes to 2 files (+1 heads)
  $ hg -R ../main rollback
  repository tip rolled back to revision 5 (undo push)
  working directory now based on revision -1

Test it still fails with checkallhook

  $ cat > ../main/.hg/hgrc <<EOF
  > [hooks]
  > pretxnchangegroup = python:hgext.eol.checkallhook
  > EOF
  $ hg push -f ../main
  pushing to ../main
  searching for changes
  adding changesets
  adding manifests
  adding file changes
  added 3 changesets with 3 changes to 2 files (+1 heads)
  error: pretxnchangegroup hook failed: end-of-line check failed:
    b.txt in fbcf9b1025f5 should not have CRLF line endings
  transaction abort!
  rollback completed
  abort: end-of-line check failed:
    b.txt in fbcf9b1025f5 should not have CRLF line endings
  [255]

But we can push the clean head

  $ hg push -r7 -f ../main
  pushing to ../main
  searching for changes
  adding changesets
  adding manifests
  adding file changes
  added 1 changesets with 1 changes to 1 files

Test multiple files/revisions output

  $ printf "another\r\nbad\r\none" > d.txt
  $ hg add d.txt
  $ hg ci -m "add d.txt"
  $ hg push -f ../main
  pushing to ../main
  searching for changes
  adding changesets
  adding manifests
  adding file changes
  added 3 changesets with 3 changes to 2 files (+1 heads)
  error: pretxnchangegroup hook failed: end-of-line check failed:
    d.txt in a7040e68714f should not have CRLF line endings
    b.txt in fbcf9b1025f5 should not have CRLF line endings
  transaction abort!
  rollback completed
  abort: end-of-line check failed:
    d.txt in a7040e68714f should not have CRLF line endings
    b.txt in fbcf9b1025f5 should not have CRLF line endings
  [255]