diff --git a/README.md b/README.md index d46f93f..968c098 100644 --- a/README.md +++ b/README.md @@ -20,7 +20,7 @@ exceptions: - Multi-line docstrings: The first line of text (summary line) appears on the same line as the opening three double-quotes. - Base Class Inheritance - If a class or nested class inherits from no other base classes, explicitly inherit from object. - - This won't be enforced for our pure Python 3 code, but we will enforce for Python 2 and 2/3 compatbile code. + - This won't be enforced for our pure Python 3 code, but we will enforce for Python 2 and 2/3 compatible code. - Variable/module-name collisions: Variable names may be suffixed with an underscore to avoid collisions with imported modules (an extension of the [PEP-8 convention](https://www.python.org/dev/peps/pep-0008/#descriptive-naming-styles) for collisions with builtins). @@ -29,7 +29,7 @@ exceptions: Projects that are producing libraries to be used in other projects should choose their release version numbers using [Semantic Versioning 2.0.0](http://semver.org/spec/v2.0.0.html), i.e. > Given a version number MAJOR.MINOR.PATCH, increment the: -> +> > MAJOR version when you make incompatible API changes, > MINOR version when you add functionality in a backwards-compatible manner, and > PATCH version when you make backwards-compatible bug fixes. diff --git a/shopify_python/git_utils.py b/shopify_python/git_utils.py index e7e24ed..39ee3c2 100644 --- a/shopify_python/git_utils.py +++ b/shopify_python/git_utils.py @@ -13,12 +13,12 @@ class GitUtilsException(Exception): pass -def _remote_origin_master(git_repo): - # type: (repo.Repo) -> head.Head - remote_master = git_repo.heads.master.tracking_branch() - if not remote_master or not remote_master.is_valid(): - raise GitUtilsException("Unable to locate remote branch origin/master") - return remote_master +def _remote_origin_branch(git_repo, branch): + # type: (repo.Repo, str) -> head.Head + remote_branch = git_repo.heads[branch].tracking_branch() + if not remote_branch or not remote_branch.is_valid(): + raise GitUtilsException("Unable to locate remote branch origin/{}".format(branch)) + return remote_branch def _modified_in_branch(git_repo, other_ref): @@ -48,12 +48,12 @@ def _file_is_python(path): return False -def changed_python_files_in_tree(root_path): - # type: (str) -> typing.List[str] +def changed_python_files_in_tree(root_path, base='master'): + # type: (str, typing.Optional[str]) -> typing.List[str] git_repo = repo.Repo(root_path) - remote_master = _remote_origin_master(git_repo) - modified = _modified_in_branch(git_repo, remote_master) + remote_branch = _remote_origin_branch(git_repo, base) + modified = _modified_in_branch(git_repo, remote_branch) abs_modified = [os.path.join(git_repo.working_dir, x) for x in modified] return [mod for (mod, abs_mod) in zip(modified, abs_modified) if os.path.exists(abs_mod) and os.path.isfile(abs_mod) and _file_is_python(abs_mod)] diff --git a/tests/shopify_python/test_git_utils.py b/tests/shopify_python/test_git_utils.py index 3dab39f..9d0435d 100644 --- a/tests/shopify_python/test_git_utils.py +++ b/tests/shopify_python/test_git_utils.py @@ -79,8 +79,8 @@ def test_detects_changed_python_files(main_repo, python_file, python_script): main_repo.create_head('foo').checkout() main_repo.index.add([python_file, python_script]) main_repo.index.commit("adding python files") - changed_files = git_utils.changed_python_files_in_tree(main_repo.working_dir) + assert sorted(changed_files) == [ os.path.basename(python_script), os.path.basename(python_file),