1744
return branch->merge[0]->dst;
1745
}
1746
1747
+static const char *tracking_for_push_dest(struct remote *remote,
1748
+ const char *refname,
1749
+ struct strbuf *err)
1750
+{
1751
+ char *ret;
1752
+
1753
+ ret = apply_refspecs(remote->fetch, remote->fetch_refspec_nr, refname);
1754
+ if (!ret)
1755
+ return error_buf(err,
1756
+ _("push destination '%s' on remote '%s' has no local tracking branch"),
1757
+ refname, remote->name);
1758
+ return ret;
1759
+}
1760
+
1761
+static const char *branch_get_push_1(struct branch *branch, struct strbuf *err)
1762
+{
1763
+ struct remote *remote;
1764
+
1765
+ if (!branch)
1766
+ return error_buf(err, _("HEAD does not point to a branch"));
1767
+
1768
+ remote = remote_get(pushremote_for_branch(branch, NULL));
1769
+ if (!remote)
1770
+ return error_buf(err,
1771
+ _("branch '%s' has no remote for pushing"),
1772
+ branch->name);
1773
+
1774
+ if (remote->push_refspec_nr) {
1775
+ char *dst;
1776
+ const char *ret;
1777
+
1778
+ dst = apply_refspecs(remote->push, remote->push_refspec_nr,
1779
+ branch->refname);
1780
+ if (!dst)
1781
+ return error_buf(err,
1782
+ _("push refspecs for '%s' do not include '%s'"),
1783
+ remote->name, branch->name);
1784
+
1785
+ ret = tracking_for_push_dest(remote, dst, err);
1786
+ free(dst);
1787
+ return ret;
1788
+ }
1789
+
1790
+ if (remote->mirror)
1791
+ return tracking_for_push_dest(remote, branch->refname, err);
1792
+
1793
+ switch (push_default) {
1794
+ case PUSH_DEFAULT_NOTHING:
1795
+ return error_buf(err, _("push has no destination (push.default is 'nothing')"));
1796
+
1797
+ case PUSH_DEFAULT_MATCHING:
1798
+ case PUSH_DEFAULT_CURRENT:
1799
+ return tracking_for_push_dest(remote, branch->refname, err);
1800
+
1801
+ case PUSH_DEFAULT_UPSTREAM:
1802
+ return branch_get_upstream(branch, err);
1803
+
1804
+ case PUSH_DEFAULT_UNSPECIFIED:
1805
+ case PUSH_DEFAULT_SIMPLE:
1806
+ {
1807
+ const char *up, *cur;
1808
+
1809
+ up = branch_get_upstream(branch, err);
1810
+ if (!up)
1811
+ return NULL;
1812
+ cur = tracking_for_push_dest(remote, branch->refname, err);
1813
+ if (!cur)
1814
+ return NULL;
1815
+ if (strcmp(cur, up))
1816
+ return error_buf(err,
1817
+ _("cannot resolve 'simple' push to a single destination"));
1818
+ return cur;
1819
+ }
1820
+ }
1821
+
1822
+ die("BUG: unhandled push situation");
1823
+}
1824
+
1825
+const char *branch_get_push(struct branch *branch, struct strbuf *err)
1826
+{
1827
+ if (!branch->push_tracking_ref)
1828
+ branch->push_tracking_ref = branch_get_push_1(branch, err);
1829
+ return branch->push_tracking_ref;
1830
+}
1831
+
1832
static int ignore_symref_update(const char *refname)
1833
{
1834
unsigned char sha1[20];