Merge branch 'mk/maint-cg-push'
* mk/maint-cg-push: git push: Interpret $GIT_DIR/branches in a Cogito compatible way Conflicts: t/t5516-fetch-push.sh
This commit is contained in:
commit
3fdd37fe15
@ -68,13 +68,22 @@ This file should have the following format:
|
|||||||
------------
|
------------
|
||||||
|
|
||||||
`<url>` is required; `#<head>` is optional.
|
`<url>` is required; `#<head>` is optional.
|
||||||
When you do not provide a refspec on the command line,
|
|
||||||
git will use the following refspec, where `<head>` defaults to `master`,
|
Depending on the operation, git will use one of the following
|
||||||
and `<repository>` is the name of this file
|
refspecs, if you don't provide one on the command line.
|
||||||
you provided in the command line.
|
`<branch>` is the name of this file in `$GIT_DIR/branches` and
|
||||||
|
`<head>` defaults to `master`.
|
||||||
|
|
||||||
|
git fetch uses:
|
||||||
|
|
||||||
------------
|
------------
|
||||||
refs/heads/<head>:<repository>
|
refs/heads/<head>:refs/heads/<branch>
|
||||||
|
------------
|
||||||
|
|
||||||
|
git push uses:
|
||||||
|
|
||||||
|
------------
|
||||||
|
HEAD:refs/heads/<head>
|
||||||
------------
|
------------
|
||||||
|
|
||||||
|
|
||||||
|
11
remote.c
11
remote.c
@ -299,6 +299,17 @@ static void read_branches_file(struct remote *remote)
|
|||||||
}
|
}
|
||||||
add_url_alias(remote, p);
|
add_url_alias(remote, p);
|
||||||
add_fetch_refspec(remote, strbuf_detach(&branch, 0));
|
add_fetch_refspec(remote, strbuf_detach(&branch, 0));
|
||||||
|
/*
|
||||||
|
* Cogito compatible push: push current HEAD to remote #branch
|
||||||
|
* (master if missing)
|
||||||
|
*/
|
||||||
|
strbuf_init(&branch, 0);
|
||||||
|
strbuf_addstr(&branch, "HEAD");
|
||||||
|
if (frag)
|
||||||
|
strbuf_addf(&branch, ":refs/heads/%s", frag);
|
||||||
|
else
|
||||||
|
strbuf_addstr(&branch, ":refs/heads/master");
|
||||||
|
add_push_refspec(remote, strbuf_detach(&branch, 0));
|
||||||
remote->fetch_tags = 1; /* always auto-follow */
|
remote->fetch_tags = 1; /* always auto-follow */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -523,4 +523,54 @@ test_expect_success 'allow push to HEAD of non-bare repository (config)' '
|
|||||||
! grep "warning.*this may cause confusion" stderr
|
! grep "warning.*this may cause confusion" stderr
|
||||||
'
|
'
|
||||||
|
|
||||||
|
test_expect_success 'fetch with branches' '
|
||||||
|
mk_empty &&
|
||||||
|
git branch second $the_first_commit &&
|
||||||
|
git checkout second &&
|
||||||
|
echo ".." > testrepo/.git/branches/branch1 &&
|
||||||
|
(cd testrepo &&
|
||||||
|
git fetch branch1 &&
|
||||||
|
r=$(git show-ref -s --verify refs/heads/branch1) &&
|
||||||
|
test "z$r" = "z$the_commit" &&
|
||||||
|
test 1 = $(git for-each-ref refs/heads | wc -l)
|
||||||
|
) &&
|
||||||
|
git checkout master
|
||||||
|
'
|
||||||
|
|
||||||
|
test_expect_success 'fetch with branches containing #' '
|
||||||
|
mk_empty &&
|
||||||
|
echo "..#second" > testrepo/.git/branches/branch2 &&
|
||||||
|
(cd testrepo &&
|
||||||
|
git fetch branch2 &&
|
||||||
|
r=$(git show-ref -s --verify refs/heads/branch2) &&
|
||||||
|
test "z$r" = "z$the_first_commit" &&
|
||||||
|
test 1 = $(git for-each-ref refs/heads | wc -l)
|
||||||
|
) &&
|
||||||
|
git checkout master
|
||||||
|
'
|
||||||
|
|
||||||
|
test_expect_success 'push with branches' '
|
||||||
|
mk_empty &&
|
||||||
|
git checkout second &&
|
||||||
|
echo "testrepo" > .git/branches/branch1 &&
|
||||||
|
git push branch1 &&
|
||||||
|
(cd testrepo &&
|
||||||
|
r=$(git show-ref -s --verify refs/heads/master) &&
|
||||||
|
test "z$r" = "z$the_first_commit" &&
|
||||||
|
test 1 = $(git for-each-ref refs/heads | wc -l)
|
||||||
|
)
|
||||||
|
'
|
||||||
|
|
||||||
|
test_expect_success 'push with branches containing #' '
|
||||||
|
mk_empty &&
|
||||||
|
echo "testrepo#branch3" > .git/branches/branch2 &&
|
||||||
|
git push branch2 &&
|
||||||
|
(cd testrepo &&
|
||||||
|
r=$(git show-ref -s --verify refs/heads/branch3) &&
|
||||||
|
test "z$r" = "z$the_first_commit" &&
|
||||||
|
test 1 = $(git for-each-ref refs/heads | wc -l)
|
||||||
|
) &&
|
||||||
|
git checkout master
|
||||||
|
'
|
||||||
|
|
||||||
test_done
|
test_done
|
||||||
|
Loading…
Reference in New Issue
Block a user