@@ -1464,6 +1464,19 @@ class PullUtil (IssueUtil):
1464
1464
infof ('Fetching {} from {}' , ref , url )
1465
1465
git_quiet (1 , 'fetch' , '--' , url , ref )
1466
1466
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
+
1467
1480
# `git hub pull` command implementation
1468
1481
class PullCmd (IssueCmd ):
1469
1482
@@ -1556,6 +1569,7 @@ class PullCmd (IssueCmd):
1556
1569
force = args .force_push )
1557
1570
infof ("Creating pull request from branch {} to {}:{}" ,
1558
1571
remote_head , config .upstream , base )
1572
+ cls .ensure_github_branch_exists (base )
1559
1573
pull = req .post (cls .url (), head = gh_head , base = base , title = title ,
1560
1574
body = body , draft = args .draft )
1561
1575
IssueCmd .UpdateCmd ._do_update (pull ['number' ], args .labels ,
@@ -1608,6 +1622,7 @@ class PullCmd (IssueCmd):
1608
1622
infof ("Attaching commits in branch {} to issue #{} "
1609
1623
"(to be merged to {}:{})" , remote_head ,
1610
1624
args .issue , config .upstream , base )
1625
+ cls .ensure_github_branch_exists (base )
1611
1626
pull = req .post (cls .url (), issue = args .issue , base = base ,
1612
1627
head = gh_head , maintainer_can_modify = False )
1613
1628
cls .print_issue_summary (pull )
0 commit comments