From 8081fd494f58eec1aeb84e3439ad8d6e190b6342 Mon Sep 17 00:00:00 2001 From: Roy Moore Date: Sat, 20 Apr 2024 12:37:55 +0300 Subject: [PATCH 1/4] Add missing index for version file update --- src/semvergit/app.py | 2 ++ src/semvergit/git_utils.py | 7 +++++++ 2 files changed, 9 insertions(+) diff --git a/src/semvergit/app.py b/src/semvergit/app.py index 777c650..603f94a 100644 --- a/src/semvergit/app.py +++ b/src/semvergit/app.py @@ -10,6 +10,7 @@ from semvergit.file_utils import update_verion_file from semvergit.git_utils import ( + add_file, get_active_branch, get_repo, get_tags_with_prefix, @@ -88,6 +89,7 @@ def update( if version_file: logger.info(f"📝 Writing version to {version_file}...") update_verion_file(version_file, new_version, dry_run) + add_file(repo=self.current_repo, file_path=version_file, dry_run=dry_run) if not commit_message: # Upading the version file requires a commit message diff --git a/src/semvergit/git_utils.py b/src/semvergit/git_utils.py index 16c4ec9..d33e22e 100644 --- a/src/semvergit/git_utils.py +++ b/src/semvergit/git_utils.py @@ -64,6 +64,13 @@ def new_commit(repo: Repo, message: str) -> str: return short_commit_id +@drywrap +def add_file(repo: Repo, file_path: str) -> None: + """Add file.""" + repo.index.add([file_path]) + logger.debug(f"Added file {file_path}") + + @drywrap def set_tag(repo: Repo, tag: str) -> VersionInfo: """Set tag.""" From d2e9840071617317ba505021d7da02295895e751 Mon Sep 17 00:00:00 2001 From: Roy Moore Date: Sat, 20 Apr 2024 12:39:16 +0300 Subject: [PATCH 2/4] Add tests for add_file --- tests/conftest.py | 10 ++++++++++ tests/test_git_utils.py | 18 ++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/tests/conftest.py b/tests/conftest.py index 41a9219..24cb938 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -110,6 +110,16 @@ def new_commit(repo: Repo, message: str, dry_run: bool) -> None: # pylint: disa monkeypatch.setattr("semvergit.app.new_commit", new_commit) +@pytest.fixture(autouse=True) +def mock_add_file(monkeypatch: MonkeyPatch) -> None: + """Mock add_file.""" + + def add_file(repo: Repo, file_path: str, dry_run: bool) -> None: # pylint: disable=unused-argument + pass + + monkeypatch.setattr("semvergit.app.add_file", add_file) + + @pytest.fixture() def mock_update_verion_file(monkeypatch: MonkeyPatch) -> None: """Mock update_verion_file.""" diff --git a/tests/test_git_utils.py b/tests/test_git_utils.py index 94d61c9..e764578 100644 --- a/tests/test_git_utils.py +++ b/tests/test_git_utils.py @@ -8,6 +8,7 @@ from pytest import MonkeyPatch, mark from semvergit.git_utils import ( + add_file, drywrap, get_active_branch, get_repo, @@ -147,6 +148,23 @@ def commit(message: str) -> MockCommit: # pylint: disable=unused-argument assert result == "112233" +def test_add_file() -> None: + """Test add_file.""" + + class MockIndex: # pylint: disable=too-few-public-methods + """Mock index.""" + + @staticmethod + def add(files: List[str]) -> None: # pylint: disable=unused-argument + """Add.""" + pass # pylint: disable=unnecessary-pass + + test_repo = Repo() + + MonkeyPatch().setattr("semvergit.git_utils.Repo.index", MockIndex) + add_file(test_repo, "testfile") + + def test_set_tag() -> None: """Test set_tag.""" From 0ac3234c007948e84903be6ed82588b33746f421 Mon Sep 17 00:00:00 2001 From: Roy Moore Date: Sat, 20 Apr 2024 12:58:25 +0300 Subject: [PATCH 3/4] Update Readme --- README.md | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 1653b65..ab4bdc1 100644 --- a/README.md +++ b/README.md @@ -32,11 +32,11 @@ I wanted a simple tool that I could use in my CI/CD pipeline to bump the version ❇️ Bump the version number and update the git tag in one command ❇️ Dry run mode ❇️ Verbose mode -❇️ Custom commit message -❇️ Auto commit message -🆕 Version 0.4+ introduces the ability to automatically update the version number in a file +❇️ Custom commit message* +❇️ Auto commit message* +🆕 Version 0.4+ introduces the ability to automatically update the version number in a file* -Please keep in mind it is designed to be used in a CI/CD pipeline (but not limited to...) +*Please see the [limitations](#Limitations) section below ## How to use @@ -69,6 +69,13 @@ Options: --help Show this message and exit. ``` +## Limitations +Please keep in mind that when using features like `commit message` / `auto commit message` and `version file` the tool will try and commit the changes to the git repo. + +Even though this is quite handy, it should be used mannually.. as it **cannot be used directly in a CI/CD pipeline directed at `master` or `main` branches** as it will likly fail due to the commit not being allowed without a PR. + +💡 Only git tags can be pushed to the remote without a PR *(and this is the main use case for this tool)*. + ## Development Please see [CONTRIBUTING.md](CONTRIBUTING.md) From 61e7a830318b0be3ec2596d9df8477384f585870 Mon Sep 17 00:00:00 2001 From: Roy Moore Date: Sat, 20 Apr 2024 12:59:52 +0300 Subject: [PATCH 4/4] Fix typo in Readme --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index ab4bdc1..9a31836 100644 --- a/README.md +++ b/README.md @@ -72,7 +72,7 @@ Options: ## Limitations Please keep in mind that when using features like `commit message` / `auto commit message` and `version file` the tool will try and commit the changes to the git repo. -Even though this is quite handy, it should be used mannually.. as it **cannot be used directly in a CI/CD pipeline directed at `master` or `main` branches** as it will likly fail due to the commit not being allowed without a PR. +Even though this is quite handy, it should be used mannually as it **cannot be used directly in a CI/CD pipeline directed at `master` or `main` branches** as it will likly fail due to the commit not being allowed without a PR. 💡 Only git tags can be pushed to the remote without a PR *(and this is the main use case for this tool)*.