Skip to content

Commit

Permalink
#75: Update changelog and avoid some 'git log' duplication
Browse files Browse the repository at this point in the history
  • Loading branch information
mtkennerly committed Feb 6, 2024
1 parent 1c50869 commit 279f746
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 31 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## Unreleased

* Fixed some `git log` commands that did not include `-c log.showsignature=false`.
([Contributed by pdecat](https://github.com/mtkennerly/dunamai/pull/75))

## v1.19.0 (2023-10-04)

* Added a `--path` option to inspect a directory other than the current one.
Expand Down
54 changes: 23 additions & 31 deletions dunamai/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,13 @@ def _get_git_version() -> List[int]:
return []


def _git_log(git_version: List[int]) -> str:
if git_version < [2, 10]:
return "git log"
else:
return "git -c log.showsignature=false log"


def _detect_vcs(expected_vcs: Optional[Vcs], path: Optional[Path]) -> Vcs:
checks = OrderedDict(
[
Expand Down Expand Up @@ -479,16 +486,9 @@ def normalize_tag_ref(ref: str) -> str:
def from_git_tag_topo_order(
tag_branch: str, git_version: List[int], path: Optional[Path]
) -> Mapping[str, int]:
if git_version < [2, 10]:
cmd = (
"git log --simplify-by-decoration --topo-order"
' --decorate=full {} "--format=%H%d"'.format(tag_branch)
)
else:
cmd = (
"git -c log.showsignature=false log --simplify-by-decoration --topo-order"
' --decorate=full {} "--format=%H%d"'.format(tag_branch)
)
cmd = (
'{} --simplify-by-decoration --topo-order --decorate=full {} "--format=%H%d"'
).format(_git_log(git_version), tag_branch)
if git_version >= [2, 16]:
cmd += " --decorate-refs=refs/tags/"
code, logmsg = _run_cmd(cmd, path)
Expand Down Expand Up @@ -1094,20 +1094,13 @@ def from_git(
else:
branch = msg

if git_version < [2, 10]:
code, msg = _run_cmd(
'git log -n 1 --format="format:{}"'.format("%H" if full_commit else "%h"),
path,
codes=[0, 128],
)
else:
code, msg = _run_cmd(
'git -c log.showsignature=false log -n 1 --format="format:{}"'.format(
"%H" if full_commit else "%h"
),
path,
codes=[0, 128],
)
code, msg = _run_cmd(
'{} -n 1 --format="format:{}"'.format(
_git_log(git_version), "%H" if full_commit else "%h"
),
path,
codes=[0, 128],
)
if code == 128:
return cls._fallback(
strict, distance=0, dirty=True, branch=branch, concerns=concerns, vcs=vcs
Expand All @@ -1116,15 +1109,14 @@ def from_git(

timestamp = None
if git_version < [2, 2]:
code, msg = _run_cmd('git log -n 1 --pretty=format:"%ci"', path)
code, msg = _run_cmd(
'{} -n 1 --pretty=format:"%ci"'.format(_git_log(git_version)), path
)
timestamp = _parse_git_timestamp_iso(msg)
else:
if git_version < [2, 10]:
code, msg = _run_cmd('git log -n 1 --pretty=format:"%cI"', path)
else:
code, msg = _run_cmd(
'git -c log.showsignature=false log -n 1 --pretty=format:"%cI"', path
)
code, msg = _run_cmd(
'{} -n 1 --pretty=format:"%cI"'.format(_git_log(git_version)), path
)
timestamp = _parse_git_timestamp_iso_strict(msg)

code, msg = _run_cmd("git describe --always --dirty", path)
Expand Down

0 comments on commit 279f746

Please sign in to comment.