Skip to content

Commit fcec406

Browse files
author
Mathieu Leduc-Hamel
committed
Adds support for linting base on branch, not only master:
1 parent 417346f commit fcec406

File tree

2 files changed

+11
-11
lines changed

2 files changed

+11
-11
lines changed

shopify_python/git_utils.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@ class GitUtilsException(Exception):
1313
pass
1414

1515

16-
def _remote_origin_master(git_repo):
17-
# type: (repo.Repo) -> head.Head
18-
remote_master = git_repo.heads.master.tracking_branch()
19-
if not remote_master or not remote_master.is_valid():
20-
raise GitUtilsException("Unable to locate remote branch origin/master")
21-
return remote_master
16+
def _remote_origin_branch(git_repo, branch):
17+
# type: (repo.Repo, str) -> head.Head
18+
remote_branch = git_repo.heads[branch].tracking_branch()
19+
if not remote_branch or not remote_branch.is_valid():
20+
raise GitUtilsException("Unable to locate remote branch origin/{}".format(branch))
21+
return remote_branch
2222

2323

2424
def _modified_in_branch(git_repo, other_ref):
@@ -48,12 +48,12 @@ def _file_is_python(path):
4848
return False
4949

5050

51-
def changed_python_files_in_tree(root_path):
52-
# type: (str) -> typing.List[str]
51+
def changed_python_files_in_tree(root_path, base='master'):
52+
# type: (str, typing.Optional[str]) -> typing.List[str]
5353

5454
git_repo = repo.Repo(root_path)
55-
remote_master = _remote_origin_master(git_repo)
56-
modified = _modified_in_branch(git_repo, remote_master)
55+
remote_branch = _remote_origin_branch(git_repo, base)
56+
modified = _modified_in_branch(git_repo, remote_branch)
5757
abs_modified = [os.path.join(git_repo.working_dir, x) for x in modified]
5858
return [mod for (mod, abs_mod) in zip(modified, abs_modified)
5959
if os.path.exists(abs_mod) and os.path.isfile(abs_mod) and _file_is_python(abs_mod)]

tests/shopify_python/test_git_utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ def test_detects_changed_python_files(main_repo, python_file, python_script):
7979
main_repo.create_head('foo').checkout()
8080
main_repo.index.add([python_file, python_script])
8181
main_repo.index.commit("adding python files")
82-
82+
import pdb; pdb.set_trace()
8383
changed_files = git_utils.changed_python_files_in_tree(main_repo.working_dir)
8484
assert sorted(changed_files) == [
8585
os.path.basename(python_script),

0 commit comments

Comments
 (0)