rorybyrne / git-plan

Git Plan - a better workflow for git
MIT License
182 stars 5 forks source link

bug: It should be possible to run `--version` when outside of a git repository #81

Closed rorybyrne closed 3 years ago

rorybyrne commented 3 years ago

Describe the bug

Currently, the tool fails to launch outside of a git repository. It simply prints an error message, for all commands.

To Reproduce

Steps to reproduce the behavior:

  1. pip install git-plan
  2. mkdir some_dir
  3. cd some_dir
  4. git-plan --version

Expected behavior

There should be git-plan 0.2.0 output.

Additional context

The core problem is that NotAGitRepository is raised from settings.load() here, which happens before the CLI is launched. The --version flag is therefore never processed.

One possible solution is to set settings["project_root"] to None in settings.load() if the exception is raised, and also make it optional in Project model. Then, individual commands can check project.is_a_git_repository() and fail if needed.

Another is to run a simple argparse in __cli__.py just to handle the --version flag. That is a little ugly, so I prefer the first option.

@JBizarri