Skip to content

Commit

Permalink
Merge pull request #297 from llucax/fix-92
Browse files Browse the repository at this point in the history
pull: Verify the existence of the base branch
  • Loading branch information
llucax authored Mar 19, 2021
2 parents 45acc2b + 2cf04f3 commit 1c67bbd
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
15 changes: 15 additions & 0 deletions git-hub
Original file line number Diff line number Diff line change
Expand Up @@ -1464,6 +1464,19 @@ class PullUtil (IssueUtil):
infof('Fetching {} from {}', ref, url)
git_quiet(1, 'fetch', '--', url, ref)

# Checks if the base branch exists (and die if it doesn't)
@staticmethod
def ensure_github_branch_exists(base):
try:
req.get('/repos/{}/branches/{}'.format(config.upstream, base))
except urllib.error.HTTPError as error:
if error.code == 404:
die("The base branch '{}' or upstream repo '{}' don't "
"exist (or you don't have enough permissions). "
"Please speficy a valid base branch using `--base` "
"and upstream repo using `git config hub.upstream "
"<owner>/<repo>`.", base, config.upstream)

# `git hub pull` command implementation
class PullCmd (IssueCmd):

Expand Down Expand Up @@ -1556,6 +1569,7 @@ class PullCmd (IssueCmd):
force=args.force_push)
infof("Creating pull request from branch {} to {}:{}",
remote_head, config.upstream, base)
cls.ensure_github_branch_exists(base)
pull = req.post(cls.url(), head=gh_head, base=base, title=title,
body=body, draft=args.draft)
IssueCmd.UpdateCmd._do_update(pull['number'], args.labels,
Expand Down Expand Up @@ -1608,6 +1622,7 @@ class PullCmd (IssueCmd):
infof("Attaching commits in branch {} to issue #{} "
"(to be merged to {}:{})", remote_head,
args.issue, config.upstream, base)
cls.ensure_github_branch_exists(base)
pull = req.post(cls.url(), issue=args.issue, base=base,
head=gh_head, maintainer_can_modify=False)
cls.print_issue_summary(pull)
Expand Down
5 changes: 5 additions & 0 deletions relnotes/pull-base.bug.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
### Check if the base branch exists when creating a PR (#92)

When creating a PR if the specified (or inferred) base branch doesn't exist,
a very weird error message was printed. Now the branch existence is explicitly
checked before attempting the PR creation.

0 comments on commit 1c67bbd

Please sign in to comment.