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

Fall back on main / master if one doesn't exist #20

Merged
merged 1 commit into from
Sep 7, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion revup/git.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@
"-U1",
]

COMMON_MAIN_BRANCHES = ["main", "master"] # Below logic assumes 2 values here


@dataclass
class CommitHeader:
Expand Down Expand Up @@ -164,12 +166,13 @@ async def get_editor() -> str:
ret = os.environ.get("GIT_EDITOR", os.environ.get("EDITOR", "nano"))
return ret

repo_root, git_dir, actual_version, email, editor = await asyncio.gather(
repo_root, git_dir, actual_version, email, editor, main_exists = await asyncio.gather(
git_ctx.git_stdout("rev-parse", "--show-toplevel"),
git_ctx.git_stdout("rev-parse", "--path-format=absolute", "--git-dir"),
git_ctx.git_stdout("--version"),
get_email(),
get_editor(),
git_ctx.commit_exists(main_branch),
)

if git_version:
Expand All @@ -189,6 +192,13 @@ async def get_editor() -> str:
git_ctx.email = email.lower()
git_ctx.author = git_ctx.email.split("@")[0]
git_ctx.editor = editor
if not main_exists:
if main_branch in COMMON_MAIN_BRANCHES:
git_ctx.main_branch = COMMON_MAIN_BRANCHES[1 - COMMON_MAIN_BRANCHES.index(main_branch)]
logging.info(
'Branch {} not found, falling back to "{}". We recommend you set this in'
" .revupconfig".format(main_branch, git_ctx.main_branch)
)
return git_ctx


Expand Down