Skip to content

Commit ca186ce

Browse files
authored
fix(facts.git): GitLocalCommit fact failing on nonlocal ref (#1881)
1 parent 2a9339f commit ca186ce

5 files changed

Lines changed: 14 additions & 4 deletions

File tree

src/pyinfra/facts/git.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ class GitLocalCommit(GitFactBase):
8383

8484
@override
8585
def command(self, repo: str, ref: str = "HEAD") -> str:
86-
return f"! test -d {repo} || (cd {repo} && git rev-parse {ref} 2>/dev/null)"
86+
return f"! test -d {repo} || (cd {repo} && git rev-parse {ref} 2>/dev/null) || true"
8787

8888
@override
8989
def process(self, output: list[str]):

tests/facts/git.GitLocalCommit/branch_ref.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"repo": "myrepo",
44
"ref": "mybranch"
55
},
6-
"command": "! test -d myrepo || (cd myrepo && git rev-parse mybranch 2>/dev/null)",
6+
"command": "! test -d myrepo || (cd myrepo && git rev-parse mybranch 2>/dev/null) || true",
77
"requires_command": "git",
88
"output": [
99
"1a2b3c4d5e6f7890abcdef1234567890abcdef12"

tests/facts/git.GitLocalCommit/head.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"arg": "myrepo",
3-
"command": "! test -d myrepo || (cd myrepo && git rev-parse HEAD 2>/dev/null)",
3+
"command": "! test -d myrepo || (cd myrepo && git rev-parse HEAD 2>/dev/null) || true",
44
"requires_command": "git",
55
"output": [
66
"1a2b3c4d5e6f7890abcdef1234567890abcdef12"

tests/facts/git.GitLocalCommit/no_repo.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"arg": "myrepo",
3-
"command": "! test -d myrepo || (cd myrepo && git rev-parse HEAD 2>/dev/null)",
3+
"command": "! test -d myrepo || (cd myrepo && git rev-parse HEAD 2>/dev/null) || true",
44
"requires_command": "git",
55
"output": [],
66
"fact": null
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"arg": {
3+
"repo": "myrepo",
4+
"ref": "v34.0.1"
5+
},
6+
"command": "! test -d myrepo || (cd myrepo && git rev-parse v34.0.1 2>/dev/null) || true",
7+
"requires_command": "git",
8+
"output": [],
9+
"fact": null
10+
}

0 commit comments

Comments
 (0)