Mercurial > public > mercurial-scm > python-hglib
annotate tests/test-commit.py @ 216:68588c652ac6
client: handle commit messages with \0 characters
Mercurial allows commit messages containing \0 characters,
but hglib does not properly handle them.
By using the json template, these characters are correctly escaped.
Note: initial change only modifies this for the 'log' command,
I'll follow-up for other commands if this is ok.
author | Mathias De Mare <mathias.de_mare@nokia.com> |
---|---|
date | Wed, 08 Mar 2023 16:22:21 +0100 |
parents | 67398bbf788d |
children |
rev | line source |
---|---|
148
c1b966866ed7
hglib: make all imports absolute (issue4520)
Brett Cannon <brett@python.org>
parents:
144
diff
changeset
|
1 from tests import common |
c1b966866ed7
hglib: make all imports absolute (issue4520)
Brett Cannon <brett@python.org>
parents:
144
diff
changeset
|
2 import hglib, datetime |
143
4359cabcb0cc
hglib: move string literals in the test code to util.b() (issue4520)
Brett Cannon <brett@python.org>
parents:
136
diff
changeset
|
3 from hglib.util import b |
16
943aff89b068
client: add missing options to commit()
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
4 |
943aff89b068
client: add missing options to commit()
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
5 class test_commit(common.basetest): |
943aff89b068
client: add missing options to commit()
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
6 def test_user(self): |
943aff89b068
client: add missing options to commit()
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
7 self.append('a', 'a') |
143
4359cabcb0cc
hglib: move string literals in the test code to util.b() (issue4520)
Brett Cannon <brett@python.org>
parents:
136
diff
changeset
|
8 rev, node = self.client.commit(b('first'), addremove=True, |
4359cabcb0cc
hglib: move string literals in the test code to util.b() (issue4520)
Brett Cannon <brett@python.org>
parents:
136
diff
changeset
|
9 user=b('foo')) |
16
943aff89b068
client: add missing options to commit()
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
10 rev = self.client.log(node)[0] |
143
4359cabcb0cc
hglib: move string literals in the test code to util.b() (issue4520)
Brett Cannon <brett@python.org>
parents:
136
diff
changeset
|
11 self.assertEquals(rev.author, b('foo')) |
16
943aff89b068
client: add missing options to commit()
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
12 |
943aff89b068
client: add missing options to commit()
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
13 def test_no_user(self): |
943aff89b068
client: add missing options to commit()
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
14 self.append('a', 'a') |
134 | 15 self.assertRaises(hglib.error.CommandError, |
143
4359cabcb0cc
hglib: move string literals in the test code to util.b() (issue4520)
Brett Cannon <brett@python.org>
parents:
136
diff
changeset
|
16 self.client.commit, b('first'), user=b('')) |
16
943aff89b068
client: add missing options to commit()
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
17 |
943aff89b068
client: add missing options to commit()
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
18 def test_close_branch(self): |
943aff89b068
client: add missing options to commit()
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
19 self.append('a', 'a') |
143
4359cabcb0cc
hglib: move string literals in the test code to util.b() (issue4520)
Brett Cannon <brett@python.org>
parents:
136
diff
changeset
|
20 rev0, node0 = self.client.commit(b('first'), addremove=True) |
4359cabcb0cc
hglib: move string literals in the test code to util.b() (issue4520)
Brett Cannon <brett@python.org>
parents:
136
diff
changeset
|
21 self.client.branch(b('foo')) |
16
943aff89b068
client: add missing options to commit()
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
22 self.append('a', 'a') |
143
4359cabcb0cc
hglib: move string literals in the test code to util.b() (issue4520)
Brett Cannon <brett@python.org>
parents:
136
diff
changeset
|
23 rev1, node1 = self.client.commit(b('second')) |
4359cabcb0cc
hglib: move string literals in the test code to util.b() (issue4520)
Brett Cannon <brett@python.org>
parents:
136
diff
changeset
|
24 revclose = self.client.commit(b('closing foo'), closebranch=True) |
16
943aff89b068
client: add missing options to commit()
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
25 rev0, rev1, revclose = self.client.log([node0, node1, revclose[1]]) |
943aff89b068
client: add missing options to commit()
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
26 |
943aff89b068
client: add missing options to commit()
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
27 self.assertEquals(self.client.branches(), |
943aff89b068
client: add missing options to commit()
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
28 [(rev0.branch, int(rev0.rev), rev0.node[:12])]) |
943aff89b068
client: add missing options to commit()
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
29 |
943aff89b068
client: add missing options to commit()
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
30 self.assertEquals(self.client.branches(closed=True), |
134 | 31 [(revclose.branch, int(revclose.rev), |
32 revclose.node[:12]), | |
16
943aff89b068
client: add missing options to commit()
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
33 (rev0.branch, int(rev0.rev), rev0.node[:12])]) |
943aff89b068
client: add missing options to commit()
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
34 |
943aff89b068
client: add missing options to commit()
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
35 def test_message_logfile(self): |
143
4359cabcb0cc
hglib: move string literals in the test code to util.b() (issue4520)
Brett Cannon <brett@python.org>
parents:
136
diff
changeset
|
36 self.assertRaises(ValueError, self.client.commit, b('foo'), |
4359cabcb0cc
hglib: move string literals in the test code to util.b() (issue4520)
Brett Cannon <brett@python.org>
parents:
136
diff
changeset
|
37 logfile=b('bar')) |
16
943aff89b068
client: add missing options to commit()
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
38 self.assertRaises(ValueError, self.client.commit) |
99
2b36619ec0a0
client: add date field to revision
Idan Kamara <idankk86@gmail.com>
parents:
16
diff
changeset
|
39 |
2b36619ec0a0
client: add date field to revision
Idan Kamara <idankk86@gmail.com>
parents:
16
diff
changeset
|
40 def test_date(self): |
2b36619ec0a0
client: add date field to revision
Idan Kamara <idankk86@gmail.com>
parents:
16
diff
changeset
|
41 self.append('a', 'a') |
2b36619ec0a0
client: add date field to revision
Idan Kamara <idankk86@gmail.com>
parents:
16
diff
changeset
|
42 now = datetime.datetime.now().replace(microsecond=0) |
143
4359cabcb0cc
hglib: move string literals in the test code to util.b() (issue4520)
Brett Cannon <brett@python.org>
parents:
136
diff
changeset
|
43 rev0, node0 = self.client.commit( |
4359cabcb0cc
hglib: move string literals in the test code to util.b() (issue4520)
Brett Cannon <brett@python.org>
parents:
136
diff
changeset
|
44 b('first'), addremove=True, |
4359cabcb0cc
hglib: move string literals in the test code to util.b() (issue4520)
Brett Cannon <brett@python.org>
parents:
136
diff
changeset
|
45 date=now.isoformat(' ').encode('latin-1')) |
99
2b36619ec0a0
client: add date field to revision
Idan Kamara <idankk86@gmail.com>
parents:
16
diff
changeset
|
46 |
2b36619ec0a0
client: add date field to revision
Idan Kamara <idankk86@gmail.com>
parents:
16
diff
changeset
|
47 self.assertEquals(now, self.client.tip().date) |
136
dc63978871ed
client: add support for 'hg commit --amend'
David Douard <david.douard@logilab.fr>
parents:
134
diff
changeset
|
48 |
dc63978871ed
client: add support for 'hg commit --amend'
David Douard <david.douard@logilab.fr>
parents:
134
diff
changeset
|
49 def test_amend(self): |
dc63978871ed
client: add support for 'hg commit --amend'
David Douard <david.douard@logilab.fr>
parents:
134
diff
changeset
|
50 self.append('a', 'a') |
dc63978871ed
client: add support for 'hg commit --amend'
David Douard <david.douard@logilab.fr>
parents:
134
diff
changeset
|
51 now = datetime.datetime.now().replace(microsecond=0) |
143
4359cabcb0cc
hglib: move string literals in the test code to util.b() (issue4520)
Brett Cannon <brett@python.org>
parents:
136
diff
changeset
|
52 rev0, node0 = self.client.commit( |
4359cabcb0cc
hglib: move string literals in the test code to util.b() (issue4520)
Brett Cannon <brett@python.org>
parents:
136
diff
changeset
|
53 b('first'), addremove=True, |
4359cabcb0cc
hglib: move string literals in the test code to util.b() (issue4520)
Brett Cannon <brett@python.org>
parents:
136
diff
changeset
|
54 date=now.isoformat(' ').encode('latin-1')) |
136
dc63978871ed
client: add support for 'hg commit --amend'
David Douard <david.douard@logilab.fr>
parents:
134
diff
changeset
|
55 |
dc63978871ed
client: add support for 'hg commit --amend'
David Douard <david.douard@logilab.fr>
parents:
134
diff
changeset
|
56 self.assertEquals(now, self.client.tip().date) |
dc63978871ed
client: add support for 'hg commit --amend'
David Douard <david.douard@logilab.fr>
parents:
134
diff
changeset
|
57 |
dc63978871ed
client: add support for 'hg commit --amend'
David Douard <david.douard@logilab.fr>
parents:
134
diff
changeset
|
58 self.append('a', 'a') |
dc63978871ed
client: add support for 'hg commit --amend'
David Douard <david.douard@logilab.fr>
parents:
134
diff
changeset
|
59 rev1, node1 = self.client.commit(amend=True) |
dc63978871ed
client: add support for 'hg commit --amend'
David Douard <david.douard@logilab.fr>
parents:
134
diff
changeset
|
60 self.assertEquals(now, self.client.tip().date) |
dc63978871ed
client: add support for 'hg commit --amend'
David Douard <david.douard@logilab.fr>
parents:
134
diff
changeset
|
61 self.assertNotEquals(node0, node1) |
dc63978871ed
client: add support for 'hg commit --amend'
David Douard <david.douard@logilab.fr>
parents:
134
diff
changeset
|
62 self.assertEqual(1, len(self.client.log())) |
201
67398bbf788d
client: do not accept NULL character as command arguments
Yuya Nishihara <yuya@tcha.org>
parents:
148
diff
changeset
|
63 |
67398bbf788d
client: do not accept NULL character as command arguments
Yuya Nishihara <yuya@tcha.org>
parents:
148
diff
changeset
|
64 def test_nul_injection(self): |
67398bbf788d
client: do not accept NULL character as command arguments
Yuya Nishihara <yuya@tcha.org>
parents:
148
diff
changeset
|
65 self.append('a', 'a') |
67398bbf788d
client: do not accept NULL character as command arguments
Yuya Nishihara <yuya@tcha.org>
parents:
148
diff
changeset
|
66 self.assertRaises(ValueError, lambda: self.client.commit(b('fail\0-A'))) |
67398bbf788d
client: do not accept NULL character as command arguments
Yuya Nishihara <yuya@tcha.org>
parents:
148
diff
changeset
|
67 self.assertEqual(0, len(self.client.log())) |