@@ -501,28 +501,6 @@ const char *pushremote_for_branch(struct branch *branch, int *explicit)
501
501
return remote_for_branch (branch , explicit );
502
502
}
503
503
504
- const char * remote_ref_for_branch (struct branch * branch , int for_push )
505
- {
506
- if (branch ) {
507
- if (!for_push ) {
508
- if (branch -> merge_nr ) {
509
- return branch -> merge_name [0 ];
510
- }
511
- } else {
512
- const char * dst , * remote_name =
513
- pushremote_for_branch (branch , NULL );
514
- struct remote * remote = remote_get (remote_name );
515
-
516
- if (remote && remote -> push .nr &&
517
- (dst = apply_refspecs (& remote -> push ,
518
- branch -> refname ))) {
519
- return dst ;
520
- }
521
- }
522
- }
523
- return NULL ;
524
- }
525
-
526
504
static struct remote * remote_get_1 (const char * name ,
527
505
const char * (* get_default )(struct branch * , int * ))
528
506
{
@@ -1738,6 +1716,64 @@ static const char *tracking_for_push_dest(struct remote *remote,
1738
1716
return ret ;
1739
1717
}
1740
1718
1719
+ /**
1720
+ * Return the local name of the remote tracking branch, as in
1721
+ * %(push:remoteref), that corresponds to the ref we would push to given a
1722
+ * bare `git push` while `branch` is checked out.
1723
+ * See also branch_get_push_1 below.
1724
+ */
1725
+ static const char * branch_get_push_remoteref (struct branch * branch )
1726
+ {
1727
+ struct remote * remote ;
1728
+
1729
+ remote = remote_get (pushremote_for_branch (branch , NULL ));
1730
+ if (!remote )
1731
+ return NULL ;
1732
+
1733
+ if (remote -> push .nr ) {
1734
+ return apply_refspecs (& remote -> push , branch -> refname );
1735
+ }
1736
+
1737
+ if (remote -> mirror )
1738
+ return branch -> refname ;
1739
+
1740
+ switch (push_default ) {
1741
+ case PUSH_DEFAULT_NOTHING :
1742
+ return NULL ;
1743
+
1744
+ case PUSH_DEFAULT_MATCHING :
1745
+ case PUSH_DEFAULT_CURRENT :
1746
+ return branch -> refname ;
1747
+
1748
+ case PUSH_DEFAULT_UPSTREAM :
1749
+ if (branch && branch -> merge && branch -> merge [0 ] &&
1750
+ branch -> merge [0 ]-> dst )
1751
+ return branch -> merge [0 ]-> src ;
1752
+ else
1753
+ return NULL ;
1754
+
1755
+ case PUSH_DEFAULT_UNSPECIFIED :
1756
+ case PUSH_DEFAULT_SIMPLE :
1757
+ {
1758
+ const char * up , * cur ;
1759
+
1760
+ up = branch_get_upstream (branch , NULL );
1761
+ cur = tracking_for_push_dest (remote , branch -> refname , NULL );
1762
+ if (up && cur && !strcmp (cur , up ))
1763
+ return branch -> refname ;
1764
+ else
1765
+ return NULL ;
1766
+
1767
+ }
1768
+ }
1769
+ BUG ("unhandled push situation" );
1770
+ }
1771
+
1772
+ /**
1773
+ * Return the tracking branch, as in %(push), that corresponds to the ref we
1774
+ * would push to given a bare `git push` while `branch` is checked out.
1775
+ * See also branch_get_push_remoteref above.
1776
+ */
1741
1777
static const char * branch_get_push_1 (struct branch * branch , struct strbuf * err )
1742
1778
{
1743
1779
struct remote * remote ;
@@ -1817,6 +1853,20 @@ static int ignore_symref_update(const char *refname)
1817
1853
return (flag & REF_ISSYMREF );
1818
1854
}
1819
1855
1856
+ const char * remote_ref_for_branch (struct branch * branch , int for_push )
1857
+ {
1858
+ if (branch ) {
1859
+ if (!for_push ) {
1860
+ if (branch -> merge_nr ) {
1861
+ return branch -> merge_name [0 ];
1862
+ }
1863
+ } else {
1864
+ return branch_get_push_remoteref (branch );
1865
+ }
1866
+ }
1867
+ return NULL ;
1868
+ }
1869
+
1820
1870
/*
1821
1871
* Create and return a list of (struct ref) consisting of copies of
1822
1872
* each remote_ref that matches refspec. refspec must be a pattern.
0 commit comments