Merge branch 'jk/at-push-sha1'

Introduce <branch>@{push} short-hand to denote the remote-tracking
branch that tracks the branch at the remote the <branch> would be
pushed to.

* jk/at-push-sha1:
  for-each-ref: accept "%(push)" format
  for-each-ref: use skip_prefix instead of starts_with
  sha1_name: implement @{push} shorthand
  sha1_name: refactor interpret_upstream_mark
  sha1_name: refactor upstream_mark
  remote.c: add branch_get_push
  remote.c: return upstream name from stat_tracking_info
  remote.c: untangle error logic in branch_get_upstream
  remote.c: report specific errors from branch_get_upstream
  remote.c: introduce branch_get_upstream helper
  remote.c: hoist read_config into remote_get_1
  remote.c: provide per-branch pushremote name
  remote.c: hoist branch.*.remote lookup out of remote_get_1
  remote.c: drop "remote" pointer from "struct branch"
  remote.c: refactor setup of branch->merge list
  remote.c: drop default_remote_name variable
This commit is contained in:
Junio C Hamano
2015-06-05 12:17:36 -07:00
14 changed files with 424 additions and 149 deletions

View File

@ -150,7 +150,7 @@ test_expect_success 'branch@{u} works when tracking a local branch' '
test_expect_success 'branch@{u} error message when no upstream' '
cat >expect <<-EOF &&
fatal: No upstream configured for branch ${sq}non-tracking${sq}
fatal: no upstream configured for branch ${sq}non-tracking${sq}
EOF
error_message non-tracking@{u} 2>actual &&
test_i18ncmp expect actual
@ -158,7 +158,7 @@ test_expect_success 'branch@{u} error message when no upstream' '
test_expect_success '@{u} error message when no upstream' '
cat >expect <<-EOF &&
fatal: No upstream configured for branch ${sq}master${sq}
fatal: no upstream configured for branch ${sq}master${sq}
EOF
test_must_fail git rev-parse --verify @{u} 2>actual &&
test_i18ncmp expect actual
@ -166,7 +166,7 @@ test_expect_success '@{u} error message when no upstream' '
test_expect_success 'branch@{u} error message with misspelt branch' '
cat >expect <<-EOF &&
fatal: No such branch: ${sq}no-such-branch${sq}
fatal: no such branch: ${sq}no-such-branch${sq}
EOF
error_message no-such-branch@{u} 2>actual &&
test_i18ncmp expect actual
@ -183,7 +183,7 @@ test_expect_success '@{u} error message when not on a branch' '
test_expect_success 'branch@{u} error message if upstream branch not fetched' '
cat >expect <<-EOF &&
fatal: Upstream branch ${sq}refs/heads/side${sq} not stored as a remote-tracking branch
fatal: upstream branch ${sq}refs/heads/side${sq} not stored as a remote-tracking branch
EOF
error_message bad-upstream@{u} 2>actual &&
test_i18ncmp expect actual

63
t/t1514-rev-parse-push.sh Executable file
View File

@ -0,0 +1,63 @@
#!/bin/sh
test_description='test <branch>@{push} syntax'
. ./test-lib.sh
resolve () {
echo "$2" >expect &&
git rev-parse --symbolic-full-name "$1" >actual &&
test_cmp expect actual
}
test_expect_success 'setup' '
git init --bare parent.git &&
git init --bare other.git &&
git remote add origin parent.git &&
git remote add other other.git &&
test_commit base &&
git push origin HEAD &&
git branch --set-upstream-to=origin/master master &&
git branch --track topic origin/master &&
git push origin topic &&
git push other topic
'
test_expect_success '@{push} with default=nothing' '
test_config push.default nothing &&
test_must_fail git rev-parse master@{push}
'
test_expect_success '@{push} with default=simple' '
test_config push.default simple &&
resolve master@{push} refs/remotes/origin/master
'
test_expect_success 'triangular @{push} fails with default=simple' '
test_config push.default simple &&
test_must_fail git rev-parse topic@{push}
'
test_expect_success '@{push} with default=current' '
test_config push.default current &&
resolve topic@{push} refs/remotes/origin/topic
'
test_expect_success '@{push} with default=matching' '
test_config push.default matching &&
resolve topic@{push} refs/remotes/origin/topic
'
test_expect_success '@{push} with pushremote defined' '
test_config push.default current &&
test_config branch.topic.pushremote other &&
resolve topic@{push} refs/remotes/other/topic
'
test_expect_success '@{push} with push refspecs' '
test_config push.default nothing &&
test_config remote.origin.push refs/heads/*:refs/heads/magic/* &&
git push &&
resolve topic@{push} refs/remotes/origin/magic/topic
'
test_done

View File

@ -28,7 +28,10 @@ test_expect_success setup '
git update-ref refs/remotes/origin/master master &&
git remote add origin nowhere &&
git config branch.master.remote origin &&
git config branch.master.merge refs/heads/master
git config branch.master.merge refs/heads/master &&
git remote add myfork elsewhere &&
git config remote.pushdefault myfork &&
git config push.default current
'
test_atom() {
@ -47,6 +50,7 @@ test_atom() {
test_atom head refname refs/heads/master
test_atom head upstream refs/remotes/origin/master
test_atom head push refs/remotes/myfork/master
test_atom head objecttype commit
test_atom head objectsize 171
test_atom head objectname $(git rev-parse refs/heads/master)
@ -83,6 +87,7 @@ test_atom head HEAD '*'
test_atom tag refname refs/tags/testtag
test_atom tag upstream ''
test_atom tag push ''
test_atom tag objecttype tag
test_atom tag objectsize 154
test_atom tag objectname $(git rev-parse refs/tags/testtag)
@ -347,6 +352,12 @@ test_expect_success 'Check that :track[short] works when upstream is invalid' '
test_cmp expected actual
'
test_expect_success '%(push) supports tracking specifiers, too' '
echo "[ahead 1]" >expected &&
git for-each-ref --format="%(push:track)" refs/heads >actual &&
test_cmp expected actual
'
cat >expected <<EOF
$(git rev-parse --short HEAD)
EOF