From 7ade8ccd3adebf1603a6f8b8617179dc6bd8896d Mon Sep 17 00:00:00 2001 From: Benjamin Dauvergne Date: Fri, 1 Mar 2019 21:37:37 +0100 Subject: [PATCH] allow working from inside the working dir --- git_redmine.py | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/git_redmine.py b/git_redmine.py index 76a7ab2..1b00de2 100644 --- a/git_redmine.py +++ b/git_redmine.py @@ -26,8 +26,11 @@ def slugify(title): return title +def get_repo(): + return git.Repo(search_parent_directories=True) + def get_config(name, default=Ellipsis): - repo = git.Repo() + repo = get_repo() reader = repo.config_reader() if not reader.has_section('redmine'): raise click.UsageError('Please add a redmine section to your git configuration') @@ -59,7 +62,7 @@ def get_redmine_api(): def set_redmine(section, option, value): - repo = git.Repo() + repo = get_repo() config_writer = repo.config_writer() if not config_writer.has_section(section): config_writer.add_section(section) @@ -84,7 +87,7 @@ def get_issue(issue_number=None): def get_current_issue(): - repo = git.Repo() + repo = get_repo() branch_name = repo.head.reference.name splitted = branch_name.rsplit('/', 1) issue_number = splitted[-1].split('-')[0] @@ -105,7 +108,7 @@ def get_current_project(): def get_patches(number_of_commits=0): - repo = git.Repo() + repo = get_repo() tempdir = tempfile.mkdtemp() if number_of_commits: ref = 'HEAD' + '~' * number_of_commits @@ -133,7 +136,7 @@ def redmine(): def shell(): import IPython api = get_redmine_api() - repo = git.Repo() + repo = get_repo() IPython.embed() @@ -188,7 +191,7 @@ def take(issue_number): '''Create or switch to a branch to fix an issue''' api = get_redmine_api() issue = api.issue.get(issue_number, include='attachments') - repo = git.Repo() + repo = get_repo() new = False for head in repo.heads: if '/%s-' % issue_number in head.name: @@ -221,7 +224,7 @@ def take(issue_number): @click.option('--issue', default=None, type=int) def apply(issue): issue = get_issue(issue) - repo = git.Repo() + repo = get_repo() apply_attachments(repo, issue)