Merge branch 'js/misc-doc-fixes'
authorJunio C Hamano <gitster@pobox.com>
Wed, 8 May 2019 15:37:27 +0000 (00:37 +0900)
committerJunio C Hamano <gitster@pobox.com>
Wed, 8 May 2019 15:37:27 +0000 (00:37 +0900)
"make check-docs", "git help -a", etc. did not account for cases
where a particular build may deliberately omit some subcommands,
which has been corrected.

* js/misc-doc-fixes:
Turn `git serve` into a test helper
test-tool: handle the `-C <directory>` option just like `git`
check-docs: do not bother checking for legacy scripts' documentation
docs: exclude documentation for commands that have been excluded
check-docs: allow command-list.txt to contain excluded commands
help -a: do not list commands that are excluded from the build
Makefile: drop the NO_INSTALL variable
remote-testgit: move it into the support directory for t5801

17 files changed:
.gitignore
Documentation/.gitignore
Documentation/Makefile
Makefile
builtin.h
builtin/serve.c [deleted file]
generate-cmdlist.sh
git-remote-testgit.sh [deleted file]
git.c
t/helper/test-serve-v2.c [new file with mode: 0644]
t/helper/test-tool.c
t/helper/test-tool.h
t/t5701-git-serve.sh
t/t5702-protocol-v2.sh
t/t5703-upload-pack-ref-in-want.sh
t/t5801-remote-helpers.sh
t/t5801/git-remote-testgit [new file with mode: 0755]
index 44c74402c8c6dedfa24a9f5da6c596c7153b9d25..2374f77a1aae580ed4f71d14e1383bd2dabebd27 100644 (file)
 /git-remote-ftps
 /git-remote-fd
 /git-remote-ext
-/git-remote-testgit
 /git-remote-testpy
 /git-remote-testsvn
 /git-repack
index bf2bf271b5678895e94810dcbdca12b0dfb7de91..9022d4835545cbf40c9537efa8ca9a7678e42673 100644 (file)
@@ -14,3 +14,4 @@ manpage-base-url.xsl
 SubmittingPatches.txt
 tmp-doc-diff/
 GIT-ASCIIDOCFLAGS
+/GIT-EXCLUDED-PROGRAMS
index 6d738f831ebaf316ac79b6a3eb9c544cd18ea7c5..dbf5a0f2762fba5c7d0fcf5f7ec322c413f2b779 100644 (file)
@@ -7,7 +7,10 @@ ARTICLES =
 SP_ARTICLES =
 OBSOLETE_HTML =
 
+-include GIT-EXCLUDED-PROGRAMS
+
 MAN1_TXT += $(filter-out \
+               $(patsubst %,%.txt,$(EXCLUDED_PROGRAMS)) \
                $(addsuffix .txt, $(ARTICLES) $(SP_ARTICLES)), \
                $(wildcard git-*.txt))
 MAN1_TXT += git.txt
index 9f1b6e8926682c82530baa597794544b89d88c3a..5143cab9bdb2b303386074877838da3741ecc76d 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -592,6 +592,7 @@ FUZZ_PROGRAMS =
 LIB_OBJS =
 PROGRAM_OBJS =
 PROGRAMS =
+EXCLUDED_PROGRAMS =
 SCRIPT_PERL =
 SCRIPT_PYTHON =
 SCRIPT_SH =
@@ -614,7 +615,6 @@ SCRIPT_SH += git-merge-resolve.sh
 SCRIPT_SH += git-mergetool.sh
 SCRIPT_SH += git-quiltimport.sh
 SCRIPT_SH += git-legacy-stash.sh
-SCRIPT_SH += git-remote-testgit.sh
 SCRIPT_SH += git-request-pull.sh
 SCRIPT_SH += git-submodule.sh
 SCRIPT_SH += git-web--browse.sh
@@ -637,17 +637,11 @@ SCRIPT_PERL += git-svn.perl
 
 SCRIPT_PYTHON += git-p4.py
 
-NO_INSTALL += git-remote-testgit
-
 # Generated files for scripts
 SCRIPT_SH_GEN = $(patsubst %.sh,%,$(SCRIPT_SH))
 SCRIPT_PERL_GEN = $(patsubst %.perl,%,$(SCRIPT_PERL))
 SCRIPT_PYTHON_GEN = $(patsubst %.py,%,$(SCRIPT_PYTHON))
 
-SCRIPT_SH_INS = $(filter-out $(NO_INSTALL),$(SCRIPT_SH_GEN))
-SCRIPT_PERL_INS = $(filter-out $(NO_INSTALL),$(SCRIPT_PERL_GEN))
-SCRIPT_PYTHON_INS = $(filter-out $(NO_INSTALL),$(SCRIPT_PYTHON_GEN))
-
 # Individual rules to allow e.g.
 # "make -C ../.. SCRIPT_PERL=contrib/foo/bar.perl build-perl-script"
 # from subdirectories like contrib/*/
@@ -657,11 +651,11 @@ build-sh-script: $(SCRIPT_SH_GEN)
 build-python-script: $(SCRIPT_PYTHON_GEN)
 
 .PHONY: install-perl-script install-sh-script install-python-script
-install-sh-script: $(SCRIPT_SH_INS)
+install-sh-script: $(SCRIPT_SH_GEN)
        $(INSTALL) $^ '$(DESTDIR_SQ)$(gitexec_instdir_SQ)'
-install-perl-script: $(SCRIPT_PERL_INS)
+install-perl-script: $(SCRIPT_PERL_GEN)
        $(INSTALL) $^ '$(DESTDIR_SQ)$(gitexec_instdir_SQ)'
-install-python-script: $(SCRIPT_PYTHON_INS)
+install-python-script: $(SCRIPT_PYTHON_GEN)
        $(INSTALL) $^ '$(DESTDIR_SQ)$(gitexec_instdir_SQ)'
 
 .PHONY: clean-perl-script clean-sh-script clean-python-script
@@ -672,9 +666,9 @@ clean-perl-script:
 clean-python-script:
        $(RM) $(SCRIPT_PYTHON_GEN)
 
-SCRIPTS = $(SCRIPT_SH_INS) \
-         $(SCRIPT_PERL_INS) \
-         $(SCRIPT_PYTHON_INS) \
+SCRIPTS = $(SCRIPT_SH_GEN) \
+         $(SCRIPT_PERL_GEN) \
+         $(SCRIPT_PYTHON_GEN) \
          git-instaweb
 
 ETAGS_TARGET = TAGS
@@ -744,6 +738,7 @@ TEST_BUILTINS_OBJS += test-repository.o
 TEST_BUILTINS_OBJS += test-revision-walking.o
 TEST_BUILTINS_OBJS += test-run-command.o
 TEST_BUILTINS_OBJS += test-scrap-cache-tree.o
+TEST_BUILTINS_OBJS += test-serve-v2.o
 TEST_BUILTINS_OBJS += test-sha1.o
 TEST_BUILTINS_OBJS += test-sha1-array.o
 TEST_BUILTINS_OBJS += test-sha256.o
@@ -1125,7 +1120,6 @@ BUILTIN_OBJS += builtin/rev-parse.o
 BUILTIN_OBJS += builtin/revert.o
 BUILTIN_OBJS += builtin/rm.o
 BUILTIN_OBJS += builtin/send-pack.o
-BUILTIN_OBJS += builtin/serve.o
 BUILTIN_OBJS += builtin/shortlog.o
 BUILTIN_OBJS += builtin/show-branch.o
 BUILTIN_OBJS += builtin/show-index.o
@@ -1342,6 +1336,7 @@ ifdef NO_CURL
        REMOTE_CURL_PRIMARY =
        REMOTE_CURL_ALIASES =
        REMOTE_CURL_NAMES =
+       EXCLUDED_PROGRAMS += git-http-fetch git-http-push
 else
        ifdef CURLDIR
                # Try "-Wl,-rpath=$(CURLDIR)/$(lib)" in such a case.
@@ -1366,7 +1361,11 @@ endif
        ifeq "$(curl_check)" "070908"
                ifndef NO_EXPAT
                        PROGRAM_OBJS += http-push.o
+               else
+                       EXCLUDED_PROGRAMS += git-http-push
                endif
+       else
+               EXCLUDED_PROGRAMS += git-http-push
        endif
        curl_check := $(shell (echo 072200; $(CURL_CONFIG) --vernum | sed -e '/^70[BC]/s/^/0/') 2>/dev/null | sort -r | sed -ne 2p)
        ifeq "$(curl_check)" "072200"
@@ -1614,6 +1613,7 @@ ifdef NO_INET_PTON
 endif
 ifdef NO_UNIX_SOCKETS
        BASIC_CFLAGS += -DNO_UNIX_SOCKETS
+       EXCLUDED_PROGRAMS += git-credential-cache git-credential-cache--daemon
 else
        LIB_OBJS += unix-socket.o
        PROGRAM_OBJS += credential-cache.o
@@ -2133,7 +2133,9 @@ $(BUILT_INS): git$X
 command-list.h: generate-cmdlist.sh command-list.txt
 
 command-list.h: $(wildcard Documentation/git*.txt) Documentation/*config.txt Documentation/config/*.txt
-       $(QUIET_GEN)$(SHELL_PATH) ./generate-cmdlist.sh command-list.txt >$@+ && mv $@+ $@
+       $(QUIET_GEN)$(SHELL_PATH) ./generate-cmdlist.sh \
+               $(patsubst %,--exclude-program %,$(EXCLUDED_PROGRAMS)) \
+               command-list.txt >$@+ && mv $@+ $@
 
 SCRIPT_DEFINES = $(SHELL_PATH_SQ):$(DIFF_SQ):$(GIT_VERSION):\
        $(localedir_SQ):$(NO_CURL):$(USE_GETTEXT_SCHEME):$(SANE_TOOL_PATH_SQ):\
@@ -2466,6 +2468,14 @@ $(VCSSVN_LIB): $(VCSSVN_OBJS)
 
 export DEFAULT_EDITOR DEFAULT_PAGER
 
+Documentation/GIT-EXCLUDED-PROGRAMS: FORCE
+       @EXCLUDED='EXCLUDED_PROGRAMS := $(EXCLUDED_PROGRAMS)'; \
+           if test x"$$EXCLUDED" != \
+               x"`cat Documentation/GIT-EXCLUDED-PROGRAMS 2>/dev/null`" ; then \
+               echo >&2 "    * new documentation flags"; \
+               echo "$$EXCLUDED" >Documentation/GIT-EXCLUDED-PROGRAMS; \
+            fi
+
 .PHONY: doc man man-perl html info pdf
 doc: man-perl
        $(MAKE) -C Documentation all
@@ -2704,7 +2714,6 @@ endif
 test_bindir_programs := $(patsubst %,bin-wrappers/%,$(BINDIR_PROGRAMS_NEED_X) $(BINDIR_PROGRAMS_NO_X) $(TEST_PROGRAMS_NEED_X))
 
 all:: $(TEST_PROGRAMS) $(test_bindir_programs)
-all:: $(NO_INSTALL)
 
 bin-wrappers/%: wrap-for-bin.sh
        @mkdir -p bin-wrappers
@@ -2991,7 +3000,7 @@ rpm::
 
 artifacts-tar:: $(ALL_PROGRAMS) $(SCRIPT_LIB) $(BUILT_INS) $(OTHER_PROGRAMS) \
                GIT-BUILD-OPTIONS $(TEST_PROGRAMS) $(test_bindir_programs) \
-               $(NO_INSTALL) $(MOFILES)
+               $(MOFILES)
        $(QUIET_SUBDIR0)templates $(QUIET_SUBDIR1) \
                SHELL_PATH='$(SHELL_PATH_SQ)' PERL_PATH='$(PERL_PATH_SQ)'
        test -n "$(ARTIFACTS_DIRECTORY)"
@@ -3040,7 +3049,7 @@ clean: profile-clean coverage-clean cocciclean
        $(RM) $(OBJECTS)
        $(RM) $(LIB_FILE) $(XDIFF_LIB) $(VCSSVN_LIB)
        $(RM) $(ALL_PROGRAMS) $(SCRIPT_LIB) $(BUILT_INS) git$X
-       $(RM) $(TEST_PROGRAMS) $(NO_INSTALL)
+       $(RM) $(TEST_PROGRAMS)
        $(RM) $(FUZZ_PROGRAMS)
        $(RM) -r bin-wrappers $(dep_dirs)
        $(RM) -r po/build/
@@ -3049,6 +3058,7 @@ clean: profile-clean coverage-clean cocciclean
        $(RM) $(GIT_TARNAME).tar.gz git-core_$(GIT_VERSION)-*.tar.gz
        $(RM) $(htmldocs).tar.gz $(manpages).tar.gz
        $(MAKE) -C Documentation/ clean
+       $(RM) Documentation/GIT-EXCLUDED-PROGRAMS
 ifndef NO_PERL
        $(MAKE) -C gitweb clean
        $(RM) -r perl/build/
@@ -3084,7 +3094,7 @@ check-docs::
                git-merge-octopus | git-merge-ours | git-merge-recursive | \
                git-merge-resolve | git-merge-subtree | \
                git-fsck-objects | git-init-db | \
-               git-remote-* | git-stage | \
+               git-remote-* | git-stage | git-legacy-* | \
                git-?*--?* ) continue ;; \
                esac ; \
                test -f "Documentation/$$v.txt" || \
@@ -3108,7 +3118,7 @@ check-docs::
                    -e 's/\.txt//'; \
        ) | while read how cmd; \
        do \
-               case " $(patsubst %$X,%,$(ALL_COMMANDS)) " in \
+               case " $(patsubst %$X,%,$(ALL_COMMANDS) $(EXCLUDED_PROGRAMS)) " in \
                *" $$cmd "*)    ;; \
                *) echo "removed but $$how: $$cmd" ;; \
                esac; \
index b78ab6e30b26f6a079c2f747c3787ead04b57962..ac552ff0d2ce1cfb2d0036cc599d54311ebd3fb7 100644 (file)
--- a/builtin.h
+++ b/builtin.h
@@ -219,7 +219,6 @@ extern int cmd_rev_parse(int argc, const char **argv, const char *prefix);
 extern int cmd_revert(int argc, const char **argv, const char *prefix);
 extern int cmd_rm(int argc, const char **argv, const char *prefix);
 extern int cmd_send_pack(int argc, const char **argv, const char *prefix);
-extern int cmd_serve(int argc, const char **argv, const char *prefix);
 extern int cmd_shortlog(int argc, const char **argv, const char *prefix);
 extern int cmd_show(int argc, const char **argv, const char *prefix);
 extern int cmd_show_branch(int argc, const char **argv, const char *prefix);
diff --git a/builtin/serve.c b/builtin/serve.c
deleted file mode 100644 (file)
index d3fd240..0000000
+++ /dev/null
@@ -1,30 +0,0 @@
-#include "cache.h"
-#include "builtin.h"
-#include "parse-options.h"
-#include "serve.h"
-
-static char const * const serve_usage[] = {
-       N_("git serve [<options>]"),
-       NULL
-};
-
-int cmd_serve(int argc, const char **argv, const char *prefix)
-{
-       struct serve_options opts = SERVE_OPTIONS_INIT;
-
-       struct option options[] = {
-               OPT_BOOL(0, "stateless-rpc", &opts.stateless_rpc,
-                        N_("quit after a single request/response exchange")),
-               OPT_BOOL(0, "advertise-capabilities", &opts.advertise_capabilities,
-                        N_("exit immediately after advertising capabilities")),
-               OPT_END()
-       };
-
-       /* ignore all unknown cmdline switches for now */
-       argc = parse_options(argc, argv, prefix, options, serve_usage,
-                            PARSE_OPT_KEEP_DASHDASH |
-                            PARSE_OPT_KEEP_UNKNOWN);
-       serve(&opts);
-
-       return 0;
-}
index 709d67405bba65f0b1d5468fe58a92fa41c30398..71158f7d8ba9c774ca6790ea8594e96accb17fce 100755 (executable)
@@ -6,7 +6,7 @@ die () {
 }
 
 command_list () {
-       grep -v '^#' "$1"
+       eval "grep -ve '^#' $exclude_programs" <"$1"
 }
 
 get_categories () {
@@ -93,6 +93,14 @@ EOF
 EOF
 }
 
+exclude_programs=
+while test "--exclude-program" = "$1"
+do
+       shift
+       exclude_programs="$exclude_programs -e \"^$1 \""
+       shift
+done
+
 echo "/* Automatically generated by generate-cmdlist.sh */
 struct cmdname_help {
        const char *name;
diff --git a/git-remote-testgit.sh b/git-remote-testgit.sh
deleted file mode 100755 (executable)
index 752c763..0000000
+++ /dev/null
@@ -1,147 +0,0 @@
-#!/bin/sh
-# Copyright (c) 2012 Felipe Contreras
-
-# The first argument can be a url when the fetch/push command was a url
-# instead of a configured remote. In this case, use a generic alias.
-if test "$1" = "testgit::$2"; then
-       alias=_
-else
-       alias=$1
-fi
-url=$2
-
-dir="$GIT_DIR/testgit/$alias"
-prefix="refs/testgit/$alias"
-
-default_refspec="refs/heads/*:${prefix}/heads/*"
-
-refspec="${GIT_REMOTE_TESTGIT_REFSPEC-$default_refspec}"
-
-test -z "$refspec" && prefix="refs"
-
-GIT_DIR="$url/.git"
-export GIT_DIR
-
-force=
-
-mkdir -p "$dir"
-
-if test -z "$GIT_REMOTE_TESTGIT_NO_MARKS"
-then
-       gitmarks="$dir/git.marks"
-       testgitmarks="$dir/testgit.marks"
-       test -e "$gitmarks" || >"$gitmarks"
-       test -e "$testgitmarks" || >"$testgitmarks"
-fi
-
-while read line
-do
-       case $line in
-       capabilities)
-               echo 'import'
-               echo 'export'
-               test -n "$refspec" && echo "refspec $refspec"
-               if test -n "$gitmarks"
-               then
-                       echo "*import-marks $gitmarks"
-                       echo "*export-marks $gitmarks"
-               fi
-               test -n "$GIT_REMOTE_TESTGIT_SIGNED_TAGS" && echo "signed-tags"
-               test -n "$GIT_REMOTE_TESTGIT_NO_PRIVATE_UPDATE" && echo "no-private-update"
-               echo 'option'
-               echo
-               ;;
-       list)
-               git for-each-ref --format='? %(refname)' 'refs/heads/'
-               head=$(git symbolic-ref HEAD)
-               echo "@$head HEAD"
-               echo
-               ;;
-       import*)
-               # read all import lines
-               while true
-               do
-                       ref="${line#* }"
-                       refs="$refs $ref"
-                       read line
-                       test "${line%% *}" != "import" && break
-               done
-
-               if test -n "$gitmarks"
-               then
-                       echo "feature import-marks=$gitmarks"
-                       echo "feature export-marks=$gitmarks"
-               fi
-
-               if test -n "$GIT_REMOTE_TESTGIT_FAILURE"
-               then
-                       echo "feature done"
-                       exit 1
-               fi
-
-               echo "feature done"
-               git fast-export \
-                       ${testgitmarks:+"--import-marks=$testgitmarks"} \
-                       ${testgitmarks:+"--export-marks=$testgitmarks"} \
-                       $refs |
-               sed -e "s#refs/heads/#${prefix}/heads/#g"
-               echo "done"
-               ;;
-       export)
-               if test -n "$GIT_REMOTE_TESTGIT_FAILURE"
-               then
-                       # consume input so fast-export doesn't get SIGPIPE;
-                       # git would also notice that case, but we want
-                       # to make sure we are exercising the later
-                       # error checks
-                       while read line; do
-                               test "done" = "$line" && break
-                       done
-                       exit 1
-               fi
-
-               before=$(git for-each-ref --format=' %(refname) %(objectname) ')
-
-               git fast-import \
-                       ${force:+--force} \
-                       ${testgitmarks:+"--import-marks=$testgitmarks"} \
-                       ${testgitmarks:+"--export-marks=$testgitmarks"} \
-                       --quiet
-
-               # figure out which refs were updated
-               git for-each-ref --format='%(refname) %(objectname)' |
-               while read ref a
-               do
-                       case "$before" in
-                       *" $ref $a "*)
-                               continue ;;     # unchanged
-                       esac
-                       if test -z "$GIT_REMOTE_TESTGIT_PUSH_ERROR"
-                       then
-                               echo "ok $ref"
-                       else
-                               echo "error $ref $GIT_REMOTE_TESTGIT_PUSH_ERROR"
-                       fi
-               done
-
-               echo
-               ;;
-       option\ *)
-               read cmd opt val <<-EOF
-               $line
-               EOF
-               case $opt in
-               force)
-                       test $val = "true" && force="true" || force=
-                       echo "ok"
-                       ;;
-               *)
-                       echo "unsupported"
-                       ;;
-               esac
-               ;;
-       '')
-               exit
-               ;;
-       esac
-done
diff --git a/git.c b/git.c
index 50da125c60a317d820cec18767ef1fc88efd56bf..1bf9c94550d9c232de2f89ef0f2b5a661e43cd79 100644 (file)
--- a/git.c
+++ b/git.c
@@ -570,7 +570,6 @@ static struct cmd_struct commands[] = {
        { "revert", cmd_revert, RUN_SETUP | NEED_WORK_TREE },
        { "rm", cmd_rm, RUN_SETUP },
        { "send-pack", cmd_send_pack, RUN_SETUP },
-       { "serve", cmd_serve, RUN_SETUP },
        { "shortlog", cmd_shortlog, RUN_SETUP_GENTLY | USE_PAGER },
        { "show", cmd_show, RUN_SETUP },
        { "show-branch", cmd_show_branch, RUN_SETUP },
diff --git a/t/helper/test-serve-v2.c b/t/helper/test-serve-v2.c
new file mode 100644 (file)
index 0000000..aee35e5
--- /dev/null
@@ -0,0 +1,31 @@
+#include "test-tool.h"
+#include "cache.h"
+#include "parse-options.h"
+#include "serve.h"
+
+static char const * const serve_usage[] = {
+       N_("test-tool serve-v2 [<options>]"),
+       NULL
+};
+
+int cmd__serve_v2(int argc, const char **argv)
+{
+       struct serve_options opts = SERVE_OPTIONS_INIT;
+
+       struct option options[] = {
+               OPT_BOOL(0, "stateless-rpc", &opts.stateless_rpc,
+                        N_("quit after a single request/response exchange")),
+               OPT_BOOL(0, "advertise-capabilities", &opts.advertise_capabilities,
+                        N_("exit immediately after advertising capabilities")),
+               OPT_END()
+       };
+       const char *prefix = setup_git_directory();
+
+       /* ignore all unknown cmdline switches for now */
+       argc = parse_options(argc, argv, prefix, options, serve_usage,
+                            PARSE_OPT_KEEP_DASHDASH |
+                            PARSE_OPT_KEEP_UNKNOWN);
+       serve(&opts);
+
+       return 0;
+}
index 53c06932c45c17bcb2981c9b1cc081df8135dded..087a8c0cc9da64d7bc276c3870b2d0faba4c2627 100644 (file)
@@ -1,6 +1,12 @@
 #include "git-compat-util.h"
 #include "test-tool.h"
 #include "trace2.h"
+#include "parse-options.h"
+
+static const char * const test_tool_usage[] = {
+       "test-tool [-C <directory>] <command [<arguments>...]]",
+       NULL
+};
 
 struct test_cmd {
        const char *name;
@@ -43,6 +49,7 @@ static struct test_cmd cmds[] = {
        { "revision-walking", cmd__revision_walking },
        { "run-command", cmd__run_command },
        { "scrap-cache-tree", cmd__scrap_cache_tree },
+       { "serve-v2", cmd__serve_v2 },
        { "sha1", cmd__sha1 },
        { "sha1-array", cmd__sha1_array },
        { "sha256", cmd__sha256 },
@@ -75,11 +82,24 @@ static NORETURN void die_usage(void)
 int cmd_main(int argc, const char **argv)
 {
        int i;
+       const char *working_directory = NULL;
+       struct option options[] = {
+               OPT_STRING('C', NULL, &working_directory, "directory",
+                          "change the working directory"),
+               OPT_END()
+       };
 
        BUG_exit_code = 99;
+       argc = parse_options(argc, argv, NULL, options, test_tool_usage,
+                            PARSE_OPT_STOP_AT_NON_OPTION |
+                            PARSE_OPT_KEEP_ARGV0);
+
        if (argc < 2)
                die_usage();
 
+       if (working_directory && chdir(working_directory) < 0)
+               die("Could not cd to '%s'", working_directory);
+
        for (i = 0; i < ARRAY_SIZE(cmds); i++) {
                if (!strcmp(cmds[i].name, argv[1])) {
                        argv++;
index ffab4d19d701e79cac1283a749e03ae8cf437e2e..7e703f3038ae433c7d8b4ef5af51d9781d6bfffb 100644 (file)
@@ -39,6 +39,7 @@ int cmd__repository(int argc, const char **argv);
 int cmd__revision_walking(int argc, const char **argv);
 int cmd__run_command(int argc, const char **argv);
 int cmd__scrap_cache_tree(int argc, const char **argv);
+int cmd__serve_v2(int argc, const char **argv);
 int cmd__sha1(int argc, const char **argv);
 int cmd__sha1_array(int argc, const char **argv);
 int cmd__sha256(int argc, const char **argv);
index fe45bf828d09cd9d95a66742ef938837d35141a3..ffb9613885904eaf474a726f6124032d13db9753 100755 (executable)
@@ -1,6 +1,6 @@
 #!/bin/sh
 
-test_description='test git-serve and server commands'
+test_description='test protocol v2 server commands'
 
 . ./test-lib.sh
 
@@ -14,7 +14,8 @@ test_expect_success 'test capability advertisement' '
        0000
        EOF
 
-       GIT_TEST_SIDEBAND_ALL=0 git serve --advertise-capabilities >out &&
+       GIT_TEST_SIDEBAND_ALL=0 test-tool serve-v2 \
+               --advertise-capabilities >out &&
        test-tool pkt-line unpack <out >actual &&
        test_cmp expect actual
 '
@@ -24,11 +25,11 @@ test_expect_success 'stateless-rpc flag does not list capabilities' '
        test-tool pkt-line pack >in <<-EOF &&
        0000
        EOF
-       git serve --stateless-rpc >out <in &&
+       test-tool serve-v2 --stateless-rpc >out <in &&
        test_must_be_empty out &&
 
        # EOF
-       git serve --stateless-rpc >out &&
+       test-tool serve-v2 --stateless-rpc >out &&
        test_must_be_empty out
 '
 
@@ -37,7 +38,7 @@ test_expect_success 'request invalid capability' '
        foobar
        0000
        EOF
-       test_must_fail git serve --stateless-rpc 2>err <in &&
+       test_must_fail test-tool serve-v2 --stateless-rpc 2>err <in &&
        test_i18ngrep "unknown capability" err
 '
 
@@ -46,7 +47,7 @@ test_expect_success 'request with no command' '
        agent=git/test
        0000
        EOF
-       test_must_fail git serve --stateless-rpc 2>err <in &&
+       test_must_fail test-tool serve-v2 --stateless-rpc 2>err <in &&
        test_i18ngrep "no command requested" err
 '
 
@@ -56,7 +57,7 @@ test_expect_success 'request invalid command' '
        agent=git/test
        0000
        EOF
-       test_must_fail git serve --stateless-rpc 2>err <in &&
+       test_must_fail test-tool serve-v2 --stateless-rpc 2>err <in &&
        test_i18ngrep "invalid command" err
 '
 
@@ -87,7 +88,7 @@ test_expect_success 'basics of ls-refs' '
        0000
        EOF
 
-       git serve --stateless-rpc <in >out &&
+       test-tool serve-v2 --stateless-rpc <in >out &&
        test-tool pkt-line unpack <out >actual &&
        test_cmp expect actual
 '
@@ -107,7 +108,7 @@ test_expect_success 'basic ref-prefixes' '
        0000
        EOF
 
-       git serve --stateless-rpc <in >out &&
+       test-tool serve-v2 --stateless-rpc <in >out &&
        test-tool pkt-line unpack <out >actual &&
        test_cmp expect actual
 '
@@ -127,7 +128,7 @@ test_expect_success 'refs/heads prefix' '
        0000
        EOF
 
-       git serve --stateless-rpc <in >out &&
+       test-tool serve-v2 --stateless-rpc <in >out &&
        test-tool pkt-line unpack <out >actual &&
        test_cmp expect actual
 '
@@ -148,7 +149,7 @@ test_expect_success 'peel parameter' '
        0000
        EOF
 
-       git serve --stateless-rpc <in >out &&
+       test-tool serve-v2 --stateless-rpc <in >out &&
        test-tool pkt-line unpack <out >actual &&
        test_cmp expect actual
 '
@@ -169,7 +170,7 @@ test_expect_success 'symrefs parameter' '
        0000
        EOF
 
-       git serve --stateless-rpc <in >out &&
+       test-tool serve-v2 --stateless-rpc <in >out &&
        test-tool pkt-line unpack <out >actual &&
        test_cmp expect actual
 '
@@ -189,7 +190,7 @@ test_expect_success 'sending server-options' '
        0000
        EOF
 
-       git serve --stateless-rpc <in >out &&
+       test-tool serve-v2 --stateless-rpc <in >out &&
        test-tool pkt-line unpack <out >actual &&
        test_cmp expect actual
 '
@@ -204,7 +205,10 @@ test_expect_success 'unexpected lines are not allowed in fetch request' '
        0000
        EOF
 
-       test_must_fail git -C server serve --stateless-rpc <in >/dev/null 2>err &&
+       (
+               cd server &&
+               test_must_fail test-tool serve-v2 --stateless-rpc
+       ) <in >/dev/null 2>err &&
        grep "unexpected line: .this-is-not-a-command." err
 '
 
index dbb4cf8881490282a9f55f596a97b908db73df69..5b33f625dddeccce7ecd68b45f115a46f7fbe93a 100755 (executable)
@@ -400,12 +400,13 @@ test_expect_success 'even with handcrafted request, filter does not work if not
        0000
        EOF
 
-       test_must_fail git -C server serve --stateless-rpc <in >/dev/null 2>err &&
+       test_must_fail test-tool -C server serve-v2 --stateless-rpc \
+               <in >/dev/null 2>err &&
        grep "unexpected line: .filter blob:none." err &&
 
        # Exercise to ensure that if advertised, filter works
        git -C server config uploadpack.allowfilter 1 &&
-       git -C server serve --stateless-rpc <in >/dev/null
+       test-tool -C server serve-v2 --stateless-rpc <in >/dev/null
 '
 
 test_expect_success 'default refspec is used to filter ref when fetchcing' '
index b6a995e8579c91874d2850ca579f87bf93f40561..0951d1bbdc26d998cdca7ed491eca557d53b2ddf 100755 (executable)
@@ -48,15 +48,15 @@ test_expect_success 'setup repository' '
 '
 
 test_expect_success 'config controls ref-in-want advertisement' '
-       git serve --advertise-capabilities >out &&
+       test-tool serve-v2 --advertise-capabilities >out &&
        ! grep -a ref-in-want out &&
 
        git config uploadpack.allowRefInWant false &&
-       git serve --advertise-capabilities >out &&
+       test-tool serve-v2 --advertise-capabilities >out &&
        ! grep -a ref-in-want out &&
 
        git config uploadpack.allowRefInWant true &&
-       git serve --advertise-capabilities >out &&
+       test-tool serve-v2 --advertise-capabilities >out &&
        grep -a ref-in-want out
 '
 
@@ -70,7 +70,7 @@ test_expect_success 'invalid want-ref line' '
        0000
        EOF
 
-       test_must_fail git serve --stateless-rpc 2>out <in &&
+       test_must_fail test-tool serve-v2 --stateless-rpc 2>out <in &&
        grep "unknown ref" out
 '
 
@@ -90,7 +90,7 @@ test_expect_success 'basic want-ref' '
        0000
        EOF
 
-       git serve --stateless-rpc >out <in &&
+       test-tool serve-v2 --stateless-rpc >out <in &&
        check_output
 '
 
@@ -112,7 +112,7 @@ test_expect_success 'multiple want-ref lines' '
        0000
        EOF
 
-       git serve --stateless-rpc >out <in &&
+       test-tool serve-v2 --stateless-rpc >out <in &&
        check_output
 '
 
@@ -133,7 +133,7 @@ test_expect_success 'mix want and want-ref' '
        0000
        EOF
 
-       git serve --stateless-rpc >out <in &&
+       test-tool serve-v2 --stateless-rpc >out <in &&
        check_output
 '
 
@@ -153,7 +153,7 @@ test_expect_success 'want-ref with ref we already have commit for' '
        0000
        EOF
 
-       git serve --stateless-rpc >out <in &&
+       test-tool serve-v2 --stateless-rpc >out <in &&
        check_output
 '
 
index aaaa722ccab016cc5847d5b6bbc5a3879a0b3fbc..d04f8007e0e34fa938bf4fccb91eff384743e616 100755 (executable)
@@ -8,6 +8,8 @@ test_description='Test remote-helper import and export commands'
 . ./test-lib.sh
 . "$TEST_DIRECTORY"/lib-gpg.sh
 
+PATH="$TEST_DIRECTORY/t5801:$PATH"
+
 compare_refs() {
        git --git-dir="$1/.git" rev-parse --verify $2 >expect &&
        git --git-dir="$3/.git" rev-parse --verify $4 >actual &&
diff --git a/t/t5801/git-remote-testgit b/t/t5801/git-remote-testgit
new file mode 100755 (executable)
index 0000000..752c763
--- /dev/null
@@ -0,0 +1,147 @@
+#!/bin/sh
+# Copyright (c) 2012 Felipe Contreras
+
+# The first argument can be a url when the fetch/push command was a url
+# instead of a configured remote. In this case, use a generic alias.
+if test "$1" = "testgit::$2"; then
+       alias=_
+else
+       alias=$1
+fi
+url=$2
+
+dir="$GIT_DIR/testgit/$alias"
+prefix="refs/testgit/$alias"
+
+default_refspec="refs/heads/*:${prefix}/heads/*"
+
+refspec="${GIT_REMOTE_TESTGIT_REFSPEC-$default_refspec}"
+
+test -z "$refspec" && prefix="refs"
+
+GIT_DIR="$url/.git"
+export GIT_DIR
+
+force=
+
+mkdir -p "$dir"
+
+if test -z "$GIT_REMOTE_TESTGIT_NO_MARKS"
+then
+       gitmarks="$dir/git.marks"
+       testgitmarks="$dir/testgit.marks"
+       test -e "$gitmarks" || >"$gitmarks"
+       test -e "$testgitmarks" || >"$testgitmarks"
+fi
+
+while read line
+do
+       case $line in
+       capabilities)
+               echo 'import'
+               echo 'export'
+               test -n "$refspec" && echo "refspec $refspec"
+               if test -n "$gitmarks"
+               then
+                       echo "*import-marks $gitmarks"
+                       echo "*export-marks $gitmarks"
+               fi
+               test -n "$GIT_REMOTE_TESTGIT_SIGNED_TAGS" && echo "signed-tags"
+               test -n "$GIT_REMOTE_TESTGIT_NO_PRIVATE_UPDATE" && echo "no-private-update"
+               echo 'option'
+               echo
+               ;;
+       list)
+               git for-each-ref --format='? %(refname)' 'refs/heads/'
+               head=$(git symbolic-ref HEAD)
+               echo "@$head HEAD"
+               echo
+               ;;
+       import*)
+               # read all import lines
+               while true
+               do
+                       ref="${line#* }"
+                       refs="$refs $ref"
+                       read line
+                       test "${line%% *}" != "import" && break
+               done
+
+               if test -n "$gitmarks"
+               then
+                       echo "feature import-marks=$gitmarks"
+                       echo "feature export-marks=$gitmarks"
+               fi
+
+               if test -n "$GIT_REMOTE_TESTGIT_FAILURE"
+               then
+                       echo "feature done"
+                       exit 1
+               fi
+
+               echo "feature done"
+               git fast-export \
+                       ${testgitmarks:+"--import-marks=$testgitmarks"} \
+                       ${testgitmarks:+"--export-marks=$testgitmarks"} \
+                       $refs |
+               sed -e "s#refs/heads/#${prefix}/heads/#g"
+               echo "done"
+               ;;
+       export)
+               if test -n "$GIT_REMOTE_TESTGIT_FAILURE"
+               then
+                       # consume input so fast-export doesn't get SIGPIPE;
+                       # git would also notice that case, but we want
+                       # to make sure we are exercising the later
+                       # error checks
+                       while read line; do
+                               test "done" = "$line" && break
+                       done
+                       exit 1
+               fi
+
+               before=$(git for-each-ref --format=' %(refname) %(objectname) ')
+
+               git fast-import \
+                       ${force:+--force} \
+                       ${testgitmarks:+"--import-marks=$testgitmarks"} \
+                       ${testgitmarks:+"--export-marks=$testgitmarks"} \
+                       --quiet
+
+               # figure out which refs were updated
+               git for-each-ref --format='%(refname) %(objectname)' |
+               while read ref a
+               do
+                       case "$before" in
+                       *" $ref $a "*)
+                               continue ;;     # unchanged
+                       esac
+                       if test -z "$GIT_REMOTE_TESTGIT_PUSH_ERROR"
+                       then
+                               echo "ok $ref"
+                       else
+                               echo "error $ref $GIT_REMOTE_TESTGIT_PUSH_ERROR"
+                       fi
+               done
+
+               echo
+               ;;
+       option\ *)
+               read cmd opt val <<-EOF
+               $line
+               EOF
+               case $opt in
+               force)
+                       test $val = "true" && force="true" || force=
+                       echo "ok"
+                       ;;
+               *)
+                       echo "unsupported"
+                       ;;
+               esac
+               ;;
+       '')
+               exit
+               ;;
+       esac
+done