Skip to content

Commit 60d94c8

Browse files
fix: Override Git config core.abbrev when reading version from SCM (#286)
* fix: Override Git config core.abbrev when reading version from SCM The configuration represents the length commit hashes are abbreviated to. As pdm-backend parses output of git describe to obtain the package version, this configuration affects format of package versions that must be represented with a commit hash part, which is quite surprising and may introduce reproducible issues. Let's override core.abbrev with auto and let git decide how long the hash should be, keeping the format of generated version consistent regardless of value of core.abbrev and fixing failures of test__get_version_from_scm__returns_default_if_tag_cannot_be_parsed[git] that occur when the git configuration is set globally. Closes: pdm-project/pdm#3490 Signed-off-by: Yao Zi <[email protected]> * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --------- Signed-off-by: Yao Zi <[email protected]> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent 6cd4d32 commit 60d94c8

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

src/pdm/backend/hooks/version/scm.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,8 @@ def git_parse_version(root: StrPath, config: Config) -> SCMVersion | None:
193193
warnings.warn(f"{repo!r} is shallow and may cause errors")
194194
describe_cmd = [
195195
git,
196+
"-c",
197+
"core.abbrev=auto",
196198
"describe",
197199
"--dirty",
198200
"--tags",

tests/pdm/backend/hooks/version/test_scm.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,10 @@ def tag(self, name: str):
139139

140140
@property
141141
def current_hash(self) -> str:
142-
return "g" + self.run("rev-parse", "--short", "HEAD").strip()
142+
return (
143+
"g"
144+
+ self.run("-c", "core.abbrev=auto", "rev-parse", "--short", "HEAD").strip()
145+
)
143146

144147

145148
class HgScm(Scm):

0 commit comments

Comments
 (0)