Merge branch 'js/remote-improvements'

* js/remote-improvements: (23 commits)
  builtin-remote.c: no "commented out" code, please
  builtin-remote: new show output style for push refspecs
  builtin-remote: new show output style
  remote: make guess_remote_head() use exact HEAD lookup if it is available
  builtin-remote: add set-head subcommand
  builtin-remote: teach show to display remote HEAD
  builtin-remote: fix two inconsistencies in the output of "show <remote>"
  builtin-remote: make get_remote_ref_states() always populate states.tracked
  builtin-remote: rename variables and eliminate redundant function call
  builtin-remote: remove unused code in get_ref_states
  builtin-remote: refactor duplicated cleanup code
  string-list: new for_each_string_list() function
  remote: make match_refs() not short-circuit
  remote: make match_refs() copy src ref before assigning to peer_ref
  remote: let guess_remote_head() optionally return all matches
  remote: make copy_ref() perform a deep copy
  remote: simplify guess_remote_head()
  move locate_head() to remote.c
  move duplicated ref_newer() to remote.c
  move duplicated get_local_heads() to remote.c
  ...

Conflicts:
	builtin-clone.c
This commit is contained in:
Junio C Hamano
2009-03-17 18:55:06 -07:00
17 changed files with 821 additions and 331 deletions

View File

@ -94,13 +94,18 @@ prepare_httpd() {
}
start_httpd() {
prepare_httpd
prepare_httpd >&3 2>&4
trap 'stop_httpd; die' EXIT
"$LIB_HTTPD_PATH" -d "$HTTPD_ROOT_PATH" \
-f "$TEST_PATH/apache.conf" $HTTPD_PARA \
-c "Listen 127.0.0.1:$LIB_HTTPD_PORT" -k start
-c "Listen 127.0.0.1:$LIB_HTTPD_PORT" -k start \
>&3 2>&4
if ! test $? = 0; then
say "skipping test, web server setup failed"
test_done
fi
}
stop_httpd() {

View File

@ -28,7 +28,7 @@ tokens_match () {
}
check_remote_track () {
actual=$(git remote show "$1" | sed -e '1,/Tracked/d') &&
actual=$(git remote show "$1" | sed -ne 's|^ \(.*\) tracked$|\1|p')
shift &&
tokens_match "$*" "$actual"
}
@ -136,47 +136,73 @@ EOF
cat > test/expect << EOF
* remote origin
URL: $(pwd)/one
Remote branch merged with 'git pull' while on branch master
HEAD branch: master
Remote branches:
master new (next fetch will store in remotes/origin)
side tracked
Local branches configured for 'git pull':
ahead merges with remote master
master merges with remote master
octopus merges with remote topic-a
and with remote topic-b
and with remote topic-c
rebase rebases onto remote master
Local refs configured for 'git push':
master pushes to master (local out of date)
master pushes to upstream (create)
* remote two
URL: ../two
HEAD branch (remote HEAD is ambiguous, may be one of the following):
another
master
New remote branch (next fetch will store in remotes/origin)
master
Tracked remote branches
side
master
Local branches pushed with 'git push'
master:upstream
+refs/tags/lastbackup
Local refs configured for 'git push':
ahead forces to master (fast forwardable)
master pushes to another (up to date)
EOF
test_expect_success 'show' '
(cd test &&
git config --add remote.origin.fetch \
refs/heads/master:refs/heads/upstream &&
git config --add remote.origin.fetch refs/heads/master:refs/heads/upstream &&
git fetch &&
git checkout -b ahead origin/master &&
echo 1 >> file &&
test_tick &&
git commit -m update file &&
git checkout master &&
git branch --track octopus origin/master &&
git branch --track rebase origin/master &&
git branch -d -r origin/master &&
git config --add remote.two.url ../two &&
git config branch.rebase.rebase true &&
git config branch.octopus.merge "topic-a topic-b topic-c" &&
(cd ../one &&
echo 1 > file &&
test_tick &&
git commit -m update file) &&
git config remote.origin.push \
refs/heads/master:refs/heads/upstream &&
git config --add remote.origin.push \
+refs/tags/lastbackup &&
git remote show origin > output &&
git config --add remote.origin.push : &&
git config --add remote.origin.push refs/heads/master:refs/heads/upstream &&
git config --add remote.origin.push +refs/tags/lastbackup &&
git config --add remote.two.push +refs/heads/ahead:refs/heads/master &&
git config --add remote.two.push refs/heads/master:refs/heads/another &&
git remote show origin two > output &&
git branch -d rebase octopus &&
test_cmp expect output)
'
cat > test/expect << EOF
* remote origin
URL: $(pwd)/one
Remote branch merged with 'git pull' while on branch master
master
Tracked remote branches
HEAD branch: (not queried)
Remote branches: (status not queried)
master
side
Local branches pushed with 'git push'
master:upstream
+refs/tags/lastbackup
Local branches configured for 'git pull':
ahead merges with remote master
master merges with remote master
Local refs configured for 'git push' (status not queried):
(matching) pushes to (matching)
refs/heads/master pushes to refs/heads/upstream
refs/tags/lastbackup forces to refs/tags/lastbackup
EOF
test_expect_success 'show -n' '
@ -197,6 +223,46 @@ test_expect_success 'prune' '
test_must_fail git rev-parse refs/remotes/origin/side)
'
test_expect_success 'set-head --delete' '
(cd test &&
git symbolic-ref refs/remotes/origin/HEAD &&
git remote set-head --delete origin &&
test_must_fail git symbolic-ref refs/remotes/origin/HEAD)
'
test_expect_success 'set-head --auto' '
(cd test &&
git remote set-head --auto origin &&
echo refs/remotes/origin/master >expect &&
git symbolic-ref refs/remotes/origin/HEAD >output &&
test_cmp expect output
)
'
cat >test/expect <<EOF
error: Multiple remote HEAD branches. Please choose one explicitly with:
git remote set-head two another
git remote set-head two master
EOF
test_expect_success 'set-head --auto fails w/multiple HEADs' '
(cd test &&
test_must_fail git remote set-head --auto two >output 2>&1 &&
test_cmp expect output)
'
cat >test/expect <<EOF
refs/remotes/origin/side2
EOF
test_expect_success 'set-head explicit' '
(cd test &&
git remote set-head origin side2 &&
git symbolic-ref refs/remotes/origin/HEAD >output &&
git remote set-head origin master &&
test_cmp expect output)
'
cat > test/expect << EOF
Pruning origin
URL: $(pwd)/one
@ -343,7 +409,7 @@ test_expect_success '"remote show" does not show symbolic refs' '
git clone one three &&
(cd three &&
git remote show origin > output &&
! grep HEAD < output &&
! grep "^ *HEAD$" < output &&
! grep -i stale < output)
'

View File

@ -11,6 +11,7 @@ This test runs various sanity checks on http-push.'
ROOT_PATH="$PWD"
LIB_HTTPD_DAV=t
LIB_HTTPD_PORT=${LIB_HTTPD_PORT-'5540'}
if git http-push > /dev/null 2>&1 || [ $? -eq 128 ]
then
@ -20,13 +21,7 @@ then
fi
. "$TEST_DIRECTORY"/lib-httpd.sh
if ! start_httpd >&3 2>&4
then
say "skipping test, web server setup failed"
test_done
exit
fi
start_httpd
test_expect_success 'setup remote repository' '
cd "$ROOT_PATH" &&

57
t/t5550-http-fetch.sh Executable file
View File

@ -0,0 +1,57 @@
#!/bin/sh
test_description='test fetching over http'
. ./test-lib.sh
if test -n "$NO_CURL"; then
say 'skipping test, git built without http support'
test_done
fi
. "$TEST_DIRECTORY"/lib-httpd.sh
LIB_HTTPD_PORT=${LIB_HTTPD_PORT-'5550'}
start_httpd
test_expect_success 'setup repository' '
echo content >file &&
git add file &&
git commit -m one
'
test_expect_success 'create http-accessible bare repository' '
mkdir "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" &&
(cd "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" &&
git --bare init &&
echo "exec git update-server-info" >hooks/post-update &&
chmod +x hooks/post-update
) &&
git remote add public "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" &&
git push public master:master
'
test_expect_success 'clone http repository' '
git clone $HTTPD_URL/repo.git clone &&
test_cmp file clone/file
'
test_expect_success 'fetch changes via http' '
echo content >>file &&
git commit -a -m two &&
git push public
(cd clone && git pull) &&
test_cmp file clone/file
'
test_expect_success 'http remote detects correct HEAD' '
git push public master:other &&
(cd clone &&
git remote set-head origin -d &&
git remote set-head origin -a &&
git symbolic-ref refs/remotes/origin/HEAD > output &&
echo refs/remotes/origin/master > expect &&
test_cmp expect output
)
'
stop_httpd
test_done