mbarkhau / bumpver

BumpVer: Automatic Versioning
https://github.com/mbarkhau/bumpver
MIT License
200 stars 36 forks source link

Bumpver update --commit cannot be invoked unless in the root of the project #245

Open yannsartori opened 4 days ago

yannsartori commented 4 days ago

Hello,

I noticed that bumpver update --commit cannot be invoked unless in the root of the project (at least for git).

Minimal reproduction:

  1. mkdir project

  2. cd project

  3. git init

  4. mkdir a

  5. Create a/pyproject.toml with the following contents:

    [project]
    name = "a"
    version = "0.1.0"
    requires-python = ">=3"
    dependencies = ["bumpver"]
    
    [tool.bumpver]
    current_version = "0.1.0"
    version_pattern = "MAJOR.MINOR.PATCH"
    
    [tool.bumpver.file_patterns]
    "pyproject.toml" = ['^version = "{version}"', '^current_version = "{version}"']
  6. pip install -e .

  7. git add pyproject.toml

  8. git commit -m "commit"

  9. Run bumpver update --patch --commit, observe output

    INFO    - Old Version: 0.1.0
    INFO    - New Version: 0.1.1
    WARNING - Version Control System not found, skipping commit.

Potential Fix

In vcs.py, VCSAPI::is_usable, there is a check

if not os.path.exists(f".{self.name}"):
    return False

which will obviously fail if not in the root. I don't think this check is necessary (at least for git), because you then invoke self.subcommands['is_usable'], which for git is git rev-parse --git-dir and works anywhere in the git project. I'm not sure if this is true for mercurial though.

I can open a PR to remove that check, but I just wanted to verify that it is indeed unnecessary before removing.

yannsartori commented 4 days ago

I forgot to indicate the main motivation, but if I have two different projects in one git repository, both of which use independent versioning, then you cannot use bumpver for them (since specifying the paths in the root would sync up both versions)

mbarkhau commented 3 days ago

I guess you could remove the check and see if the test suite passes (YOLO). Also, I think this request is similar to #220.

More fundamentally, the question to answer for this issue is how to deal with git tags. Since you are handling multiple projects in the same repo, how can bumpver determine which version tags belong to which project?