Skip to content
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

Support non-master default branches #34

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
24 changes: 13 additions & 11 deletions bellybutton/cli.py
Expand Up @@ -111,19 +111,21 @@ def open_python_files(filepaths):


def get_git_modified(project_directory):
"""Get all modified filepaths between current ref and origin/master."""
subprocess.check_call(
'git -C "{}" fetch origin'.format(project_directory),
shell=True
)
diff_cmd = 'git -C "{}" diff {{}} --name-only'.format(os.path.abspath(project_directory))
"""Get all modified filepaths between current ref and default branch."""
# guess default branch based on the HEAD branch of 'origin' remote
default_branch = subprocess.run(
["git", "symbolic-ref", "refs/remotes/origin/HEAD"],
check=True, encoding="utf-8", stdout=subprocess.PIPE,
).stdout.strip().split("/")[-1]

# return files modified in staging area or compared to default branch
return frozenset(
os.path.abspath(path)
for diff in ('--staged', 'origin/master...')
for path in subprocess.check_output(
diff_cmd.format(diff),
shell=True
).decode('utf-8').strip().splitlines()
for diff in ('--staged', f"{default_branch}...")
for path in subprocess.run(
["git", "-C", project_directory, "diff", diff, "--name-only"],
check=True, encoding="utf-8", stdout=subprocess.PIPE,
).stdout.strip().splitlines()
if os.path.splitext(path)[-1] == '.py'
)

Expand Down