Skip to content

Commit 92c0ca9

Browse files
committed
show alternative ways to get current branch
1 parent f24dd83 commit 92c0ca9

File tree

3 files changed

+11
-2
lines changed

3 files changed

+11
-2
lines changed

LICENSE renamed to LICENSE.txt

File renamed without changes.

gitutils/branch.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
"""
22
Operations for Git branches
3+
4+
git branch get name methods:
5+
https://stackoverflow.com/a/45028375
36
"""
47

58
from typing import List, Tuple
@@ -9,6 +12,11 @@
912

1013
from .git import baddir, GITEXE
1114

15+
BRANCH_REV = ['rev-parse', '--abbrev-ref', 'HEAD']
16+
BRANCH_SYM = ['symbolic-ref', '--short', 'HEAD']
17+
BRANCH_NAME = ['name-rev', '--name-only', 'HEAD']
18+
BRANCH_SIMPLE = ['branch', '--show-current'] # Git >= 2.22
19+
1220

1321
async def findbranch(mainbranch: str, rdir: Path) -> List[Tuple[Path, str]]:
1422
"""
@@ -61,7 +69,7 @@ async def _arbiter(mainbranch: str, path: Path) -> Tuple[Path, str]:
6169

6270
async def _worker(mainbranch: str, path: Path) -> Tuple[Path, str]:
6371

64-
proc = await asyncio.create_subprocess_exec(*[GITEXE, '-C', str(path), 'rev-parse', '--abbrev-ref', 'HEAD'],
72+
proc = await asyncio.create_subprocess_exec(*[GITEXE, '-C', str(path)] + BRANCH_REV,
6573
stdout=asyncio.subprocess.PIPE)
6674
stdout, _ = await proc.communicate()
6775

setup.cfg

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ classifiers =
2323
Programming Language :: Python :: 3.7
2424
Programming Language :: Python :: 3.8
2525
Topic :: Utilities
26-
license_file = LICENSE
26+
license_files =
27+
LICENSE.txt
2728
long_description = file: README.md
2829
long_description_content_type = text/markdown
2930

0 commit comments

Comments
 (0)