Skip to content

Add new class SnoContext - resolves --repo consistently #35

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Mar 18, 2020
Merged

Conversation

olsen232
Copy link
Collaborator

Lots of sno commands will need machine readable output (ie, json)...
... including reporting errors in a consistent, machine readable way.

In order that "non-existent repo" is reported in a consistent way, I have moved the non-existent repo error handling code into the context object itself. In a follow up change, I will make sure that this error is output using json when json flag is set.

At least two (very minor) bugs were fixed as a side effect of this:

  • Some subcommands catch and re-raise a GitError as a click.BadParameter, but not all do (eg sno diff) - instead they test if the the repo returned is falsey, but this is not how pygit2 works.
  • In cli.py, code tests for ctx.obj["repo_dir"] - but this string is always truthy, it defaults to "." - the result of this being always-true is that the flag "-C ." is always passed to the git executable, even if this is not the user's intent. (It doesn't seem to matter much though).

@rcoup
Copy link
Contributor

rcoup commented Mar 18, 2020

Some subcommands catch and re-raise a GitError as a click.BadParameter, but not all do (eg sno diff) - instead they test if the the repo returned is falsey, but this is not how pygit2 works.

Yeah, some of this is leftovers from the initial GitPython prototype. Good catch 👍

@rcoup
Copy link
Contributor

rcoup commented Mar 18, 2020

the flag "-C ." is always passed to the git executable, even if this is not the user's intent. (It doesn't seem to matter much though).

I think this is ok, means it won't pick up any unexpected GIT_DIR environment setting.

Copy link
Contributor

@rcoup rcoup left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is great, cleans up a pile of inconsistent cruft

@olsen232 olsen232 merged commit 43c4d7e into master Mar 18, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants