Skip to content

Commit de6185f

Browse files
committed
Test for experimental "extract_status" for git status --porcelain=2
1 parent d4ccd4d commit de6185f

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

tests/test_git.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
import datetime
66
import os
7+
import re
8+
import textwrap
79

810
import pytest
911

@@ -201,3 +203,30 @@ def test_set_remote(git_repo, repo_name, new_repo_url):
201203
assert new_repo_url in git_repo.remote(
202204
name='myrepo'
203205
), 'Running remove_set should overwrite previous remote'
206+
207+
208+
def extract_status(value):
209+
"""Returns `git status -sb --porcelain=2` extracted to a dict"""
210+
pattern = re.compile(
211+
r"""
212+
^.*branch.oid\W+(?P<branch_oid>[a-f0-9]{40})[\n\r]?
213+
\#\W+branch.head[\W]+(?P<branch_head>[\w-]*)
214+
""",
215+
re.VERBOSE | re.MULTILINE,
216+
)
217+
matches = pattern.search(value)
218+
return matches.groupdict()
219+
220+
221+
def test_extract_status():
222+
FIXTURE_A = textwrap.dedent(
223+
"""
224+
# branch.oid d4ccd4d6af04b53949f89fbf0cdae13719dc5a08
225+
# branch.head fix-current-remote-name
226+
1 .M N... 100644 100644 100644 91082f119279b6f105ee9a5ce7795b3bdbe2b0de 91082f119279b6f105ee9a5ce7795b3bdbe2b0de CHANGES
227+
""" # NOQA: E501
228+
)
229+
assert {
230+
"branch_oid": 'd4ccd4d6af04b53949f89fbf0cdae13719dc5a08',
231+
"branch_head": 'fix-current-remote-name',
232+
}.items() <= extract_status(FIXTURE_A).items()

0 commit comments

Comments
 (0)