From f11c8c89f8588e96ab309bd018b9ff00bd108898 Mon Sep 17 00:00:00 2001 From: Manuel Barkhau Date: Thu, 17 Sep 2020 23:46:30 +0000 Subject: [PATCH] inc BUILD by +1000 if < 1000 --- CHANGELOG.md | 1 + src/pycalver2/version.py | 7 ++++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 957b86c..c2f31a7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ - New gitlab #7: New style patterns, to be in line with CalVer.org - Better support for week numbering. - Better support for optional parts. + - New: Start `BUILD` parts at `1000` to avoid leading zero truncation. - New gitlab #10: `--pin-date` to keep date parts unchanged, and only increment non-date parts. - Fix gitlab #8: Push tags only pushed tags, not actual commit. - Fix gitlab #9: Make commit message configurable. diff --git a/src/pycalver2/version.py b/src/pycalver2/version.py index e705293..5a6bc5a 100644 --- a/src/pycalver2/version.py +++ b/src/pycalver2/version.py @@ -486,7 +486,12 @@ def incr( else: logger.warning(f"Version appears to be from the future '{old_version}'") - cur_vinfo = cur_vinfo._replace(bid=lexid.incr(cur_vinfo.bid)) + _bid = cur_vinfo.bid + if int(_bid) < 1000: + # prevent truncation of leading zeros + _bid = str(int(_bid) + 1000) + + cur_vinfo = cur_vinfo._replace(bid=lexid.incr(_bid)) if major: cur_vinfo = cur_vinfo._replace(major=cur_vinfo.major + 1, minor=0, patch=0)