865
test_cmp expect actual
866
'
867
868
+setup_negotiation_tip () {
869
+ SERVER="$1"
870
+ URL="$2"
871
+ USE_PROTOCOL_V2="$3"
872
+
873
+ rm -rf "$SERVER" client trace &&
874
+ git init "$SERVER" &&
875
+ test_commit -C "$SERVER" alpha_1 &&
876
+ test_commit -C "$SERVER" alpha_2 &&
877
+ git -C "$SERVER" checkout --orphan beta &&
878
+ test_commit -C "$SERVER" beta_1 &&
879
+ test_commit -C "$SERVER" beta_2 &&
880
+
881
+ git clone "$URL" client &&
882
+
883
+ if test "$USE_PROTOCOL_V2" -eq 1
884
+ then
885
+ git -C "$SERVER" config protocol.version 2 &&
886
+ git -C client config protocol.version 2
887
+ fi &&
888
+
889
+ test_commit -C "$SERVER" beta_s &&
890
+ git -C "$SERVER" checkout master &&
891
+ test_commit -C "$SERVER" alpha_s &&
892
+ git -C "$SERVER" tag -d alpha_1 alpha_2 beta_1 beta_2
893
+}
894
+
895
+check_negotiation_tip () {
896
+ # Ensure that {alpha,beta}_1 are sent as "have", but not {alpha_beta}_2
897
+ ALPHA_1=$(git -C client rev-parse alpha_1) &&
898
+ grep "fetch> have $ALPHA_1" trace &&
899
+ BETA_1=$(git -C client rev-parse beta_1) &&
900
+ grep "fetch> have $BETA_1" trace &&
901
+ ALPHA_2=$(git -C client rev-parse alpha_2) &&
902
+ ! grep "fetch> have $ALPHA_2" trace &&
903
+ BETA_2=$(git -C client rev-parse beta_2) &&
904
+ ! grep "fetch> have $BETA_2" trace
905
+}
906
+
907
+test_expect_success '--negotiation-tip limits "have" lines sent' '
908
+ setup_negotiation_tip server server 0 &&
909
+ GIT_TRACE_PACKET="$(pwd)/trace" git -C client fetch \
910
+ --negotiation-tip=alpha_1 --negotiation-tip=beta_1 \
911
+ origin alpha_s beta_s &&
912
+ check_negotiation_tip
913
+'
914
+
915
+test_expect_success '--negotiation-tip understands globs' '
916
+ setup_negotiation_tip server server 0 &&
917
+ GIT_TRACE_PACKET="$(pwd)/trace" git -C client fetch \
918
+ --negotiation-tip=*_1 \
919
+ origin alpha_s beta_s &&
920
+ check_negotiation_tip
921
+'
922
+
923
+test_expect_success '--negotiation-tip understands abbreviated SHA-1' '
924
+ setup_negotiation_tip server server 0 &&
925
+ GIT_TRACE_PACKET="$(pwd)/trace" git -C client fetch \
926
+ --negotiation-tip=$(git -C client rev-parse --short alpha_1) \
927
+ --negotiation-tip=$(git -C client rev-parse --short beta_1) \
928
+ origin alpha_s beta_s &&
929
+ check_negotiation_tip
930
+'
931
+
932
+. "$TEST_DIRECTORY"/lib-httpd.sh
933
+start_httpd
934
+
935
+test_expect_success '--negotiation-tip limits "have" lines sent with HTTP protocol v2' '
936
+ setup_negotiation_tip "$HTTPD_DOCUMENT_ROOT_PATH/server" \
937
+ "$HTTPD_URL/smart/server" 1 &&
938
+ GIT_TRACE_PACKET="$(pwd)/trace" git -C client fetch \
939
+ --negotiation-tip=alpha_1 --negotiation-tip=beta_1 \
940
+ origin alpha_s beta_s &&
941
+ check_negotiation_tip
942
+'
943
+
944
+stop_httpd
945
+
946
test_done