Skip to content

Commit ecfc173

Browse files
git.GitBranch: support checking out tags (#639)
* git.GitBranch: support checking out tags Checking out a git repo is a last resort, so I always like to pin them to tags when I do have to have one on a host. `git describe` is considered plumbing and thus format stable. This behavior was introduced in 2005, so there are no real concerns that a host will be running an existing version of git that doesn't support the command or the `--all` flag. * Update git branch test to match git describe output. Co-authored-by: Nick Barrett <[email protected]>
1 parent 0e6c613 commit ecfc173

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

pyinfra/facts/git.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,11 @@ class GitBranch(FactBase):
1010

1111
@staticmethod
1212
def command(repo):
13-
return '! test -d {0} || (cd {0} && git rev-parse --abbrev-ref HEAD)'.format(repo)
13+
return '! test -d {0} || (cd {0} && git describe --all)'.format(repo)
14+
15+
@staticmethod
16+
def process(output):
17+
return re.sub(r'(heads|tags)/', r'', '\n'.join(output))
1418

1519

1620
class GitConfig(FactBase):
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
{
22
"arg": "myrepo",
3-
"command": "! test -d myrepo || (cd myrepo && git rev-parse --abbrev-ref HEAD)",
3+
"command": "! test -d myrepo || (cd myrepo && git describe --all)",
44
"requires_command": "git",
55
"output": [
6-
"develop"
6+
"heads/develop"
77
],
88
"fact": "develop"
99
}

0 commit comments

Comments
 (0)