| 1902 | } |
| 1903 | |
| 1904 | static char *branch_get_push_1(struct repository *repo, |
| 1905 | struct branch *branch, struct strbuf *err) |
| 1906 | { |
| 1907 | struct remote_state *remote_state = repo->remote_state; |
| 1908 | struct remote *remote; |
| 1909 | |
| 1910 | remote = remotes_remote_get( |
| 1911 | repo, |
| 1912 | remotes_pushremote_for_branch(remote_state, branch, NULL)); |
| 1913 | if (!remote) |
| 1914 | return error_buf(err, |
| 1915 | _("branch '%s' has no remote for pushing"), |
| 1916 | branch->name); |
| 1917 | |
| 1918 | if (remote->push.nr) { |
| 1919 | char *dst; |
| 1920 | char *ret; |
| 1921 | |
| 1922 | dst = apply_refspecs(&remote->push, branch->refname); |
| 1923 | if (!dst) |
| 1924 | return error_buf(err, |
| 1925 | _("push refspecs for '%s' do not include '%s'"), |
| 1926 | remote->name, branch->name); |
| 1927 | |
| 1928 | ret = tracking_for_push_dest(remote, dst, err); |
| 1929 | free(dst); |
| 1930 | return ret; |
| 1931 | } |
| 1932 | |
| 1933 | if (remote->mirror) |
| 1934 | return tracking_for_push_dest(remote, branch->refname, err); |
| 1935 | |
| 1936 | switch (push_default) { |
| 1937 | case PUSH_DEFAULT_NOTHING: |
| 1938 | return error_buf(err, _("push has no destination (push.default is 'nothing')")); |
| 1939 | |
| 1940 | case PUSH_DEFAULT_MATCHING: |
| 1941 | case PUSH_DEFAULT_CURRENT: |
| 1942 | return tracking_for_push_dest(remote, branch->refname, err); |
| 1943 | |
| 1944 | case PUSH_DEFAULT_UPSTREAM: |
| 1945 | return xstrdup_or_null(branch_get_upstream(branch, err)); |
| 1946 | |
| 1947 | case PUSH_DEFAULT_UNSPECIFIED: |
| 1948 | case PUSH_DEFAULT_SIMPLE: |
| 1949 | { |
| 1950 | const char *up; |
| 1951 | char *cur; |
| 1952 | |
| 1953 | up = branch_get_upstream(branch, err); |
| 1954 | if (!up) |
| 1955 | return NULL; |
| 1956 | cur = tracking_for_push_dest(remote, branch->refname, err); |
| 1957 | if (!cur) |
| 1958 | return NULL; |
| 1959 | if (strcmp(cur, up)) { |
| 1960 | free(cur); |
| 1961 | return error_buf(err, |
no test coverage detected