Skip to content

Commit 1c67bbd

Browse files
authored
Merge pull request #297 from llucax/fix-92
pull: Verify the existence of the base branch
2 parents 45acc2b + 2cf04f3 commit 1c67bbd

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

git-hub

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1464,6 +1464,19 @@ class PullUtil (IssueUtil):
14641464
infof('Fetching {} from {}', ref, url)
14651465
git_quiet(1, 'fetch', '--', url, ref)
14661466

1467+
# Checks if the base branch exists (and die if it doesn't)
1468+
@staticmethod
1469+
def ensure_github_branch_exists(base):
1470+
try:
1471+
req.get('/repos/{}/branches/{}'.format(config.upstream, base))
1472+
except urllib.error.HTTPError as error:
1473+
if error.code == 404:
1474+
die("The base branch '{}' or upstream repo '{}' don't "
1475+
"exist (or you don't have enough permissions). "
1476+
"Please speficy a valid base branch using `--base` "
1477+
"and upstream repo using `git config hub.upstream "
1478+
"<owner>/<repo>`.", base, config.upstream)
1479+
14671480
# `git hub pull` command implementation
14681481
class PullCmd (IssueCmd):
14691482

@@ -1556,6 +1569,7 @@ class PullCmd (IssueCmd):
15561569
force=args.force_push)
15571570
infof("Creating pull request from branch {} to {}:{}",
15581571
remote_head, config.upstream, base)
1572+
cls.ensure_github_branch_exists(base)
15591573
pull = req.post(cls.url(), head=gh_head, base=base, title=title,
15601574
body=body, draft=args.draft)
15611575
IssueCmd.UpdateCmd._do_update(pull['number'], args.labels,
@@ -1608,6 +1622,7 @@ class PullCmd (IssueCmd):
16081622
infof("Attaching commits in branch {} to issue #{} "
16091623
"(to be merged to {}:{})", remote_head,
16101624
args.issue, config.upstream, base)
1625+
cls.ensure_github_branch_exists(base)
16111626
pull = req.post(cls.url(), issue=args.issue, base=base,
16121627
head=gh_head, maintainer_can_modify=False)
16131628
cls.print_issue_summary(pull)

relnotes/pull-base.bug.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
### Check if the base branch exists when creating a PR (#92)
2+
3+
When creating a PR if the specified (or inferred) base branch doesn't exist,
4+
a very weird error message was printed. Now the branch existence is explicitly
5+
checked before attempting the PR creation.

0 commit comments

Comments
 (0)