@@ -505,28 +505,6 @@ const char *pushremote_for_branch(struct branch *branch, int *explicit)
505
505
return remote_for_branch (branch , explicit );
506
506
}
507
507
508
- const char * remote_ref_for_branch (struct branch * branch , int for_push )
509
- {
510
- if (branch ) {
511
- if (!for_push ) {
512
- if (branch -> merge_nr ) {
513
- return branch -> merge_name [0 ];
514
- }
515
- } else {
516
- const char * dst , * remote_name =
517
- pushremote_for_branch (branch , NULL );
518
- struct remote * remote = remote_get (remote_name );
519
-
520
- if (remote && remote -> push .nr &&
521
- (dst = apply_refspecs (& remote -> push ,
522
- branch -> refname ))) {
523
- return dst ;
524
- }
525
- }
526
- }
527
- return NULL ;
528
- }
529
-
530
508
static struct remote * remote_get_1 (const char * name ,
531
509
const char * (* get_default )(struct branch * , int * ))
532
510
{
@@ -1645,6 +1623,64 @@ static const char *tracking_for_push_dest(struct remote *remote,
1645
1623
return ret ;
1646
1624
}
1647
1625
1626
+ /**
1627
+ * Return the local name of the remote tracking branch, as in
1628
+ * %(push:remoteref), that corresponds to the ref we would push to given a
1629
+ * bare `git push` while `branch` is checked out.
1630
+ * See also branch_get_push_1 below.
1631
+ */
1632
+ static const char * branch_get_push_remoteref (struct branch * branch )
1633
+ {
1634
+ struct remote * remote ;
1635
+
1636
+ remote = remote_get (pushremote_for_branch (branch , NULL ));
1637
+ if (!remote )
1638
+ return NULL ;
1639
+
1640
+ if (remote -> push .nr ) {
1641
+ return apply_refspecs (& remote -> push , branch -> refname );
1642
+ }
1643
+
1644
+ if (remote -> mirror )
1645
+ return branch -> refname ;
1646
+
1647
+ switch (push_default ) {
1648
+ case PUSH_DEFAULT_NOTHING :
1649
+ return NULL ;
1650
+
1651
+ case PUSH_DEFAULT_MATCHING :
1652
+ case PUSH_DEFAULT_CURRENT :
1653
+ return branch -> refname ;
1654
+
1655
+ case PUSH_DEFAULT_UPSTREAM :
1656
+ if (branch && branch -> merge && branch -> merge [0 ] &&
1657
+ branch -> merge [0 ]-> dst )
1658
+ return branch -> merge [0 ]-> src ;
1659
+ else
1660
+ return NULL ;
1661
+
1662
+ case PUSH_DEFAULT_UNSPECIFIED :
1663
+ case PUSH_DEFAULT_SIMPLE :
1664
+ {
1665
+ const char * up , * cur ;
1666
+
1667
+ up = branch_get_upstream (branch , NULL );
1668
+ cur = tracking_for_push_dest (remote , branch -> refname , NULL );
1669
+ if (up && cur && !strcmp (cur , up ))
1670
+ return branch -> refname ;
1671
+ else
1672
+ return NULL ;
1673
+
1674
+ }
1675
+ }
1676
+ BUG ("unhandled push situation" );
1677
+ }
1678
+
1679
+ /**
1680
+ * Return the tracking branch, as in %(push), that corresponds to the ref we
1681
+ * would push to given a bare `git push` while `branch` is checked out.
1682
+ * See also branch_get_push_remoteref above.
1683
+ */
1648
1684
static const char * branch_get_push_1 (struct branch * branch , struct strbuf * err )
1649
1685
{
1650
1686
struct remote * remote ;
@@ -1724,6 +1760,20 @@ static int ignore_symref_update(const char *refname)
1724
1760
return (flag & REF_ISSYMREF );
1725
1761
}
1726
1762
1763
+ const char * remote_ref_for_branch (struct branch * branch , int for_push )
1764
+ {
1765
+ if (branch ) {
1766
+ if (!for_push ) {
1767
+ if (branch -> merge_nr ) {
1768
+ return branch -> merge_name [0 ];
1769
+ }
1770
+ } else {
1771
+ return branch_get_push_remoteref (branch );
1772
+ }
1773
+ }
1774
+ return NULL ;
1775
+ }
1776
+
1727
1777
/*
1728
1778
* Create and return a list of (struct ref) consisting of copies of
1729
1779
* each remote_ref that matches refspec. refspec must be a pattern.
0 commit comments