From 5afb2ce4cd19b272c218ef5901265c2519204144 Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Fri, 12 Apr 2019 05:00:31 -0700 Subject: remote-testgit: move it into the support directory for t5801 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The `git-remote-testgit` script is really only used in `t5801-remote-helpers.sh`. It does not even contain any `@@@@` placeholders that would need to be interpolated via `make git-remote-testgit`. Let's just move it to a new home, decluttering the top-level directory and clarifying that this is just a test helper, not an official Git command that we would want to ever support. Suggested by Ævar Arnfjörð Bjarmason. Signed-off-by: Johannes Schindelin Signed-off-by: Junio C Hamano diff --git a/.gitignore b/.gitignore index 7374587..de8fc2f 100644 --- a/.gitignore +++ b/.gitignore @@ -135,7 +135,6 @@ /git-remote-ftps /git-remote-fd /git-remote-ext -/git-remote-testgit /git-remote-testpy /git-remote-testsvn /git-repack diff --git a/Makefile b/Makefile index 8654c13..26f8ed2 100644 --- a/Makefile +++ b/Makefile @@ -633,7 +633,6 @@ SCRIPT_SH += git-merge-resolve.sh SCRIPT_SH += git-mergetool.sh SCRIPT_SH += git-quiltimport.sh SCRIPT_SH += git-legacy-rebase.sh -SCRIPT_SH += git-remote-testgit.sh SCRIPT_SH += git-request-pull.sh SCRIPT_SH += git-stash.sh SCRIPT_SH += git-submodule.sh @@ -657,8 +656,6 @@ 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)) diff --git a/git-remote-testgit.sh b/git-remote-testgit.sh deleted file mode 100755 index 752c763..0000000 --- a/git-remote-testgit.sh +++ /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/t/t5801-remote-helpers.sh b/t/t5801-remote-helpers.sh index aaaa722..d04f800 100755 --- a/t/t5801-remote-helpers.sh +++ b/t/t5801-remote-helpers.sh @@ -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 index 0000000..752c763 --- /dev/null +++ b/t/t5801/git-remote-testgit @@ -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 -- cgit v0.10.2-6-g49f6 From 0b64e21cc220a73f7a49d932d44e8cfc11532d0f Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Thu, 18 Apr 2019 06:16:39 -0700 Subject: Makefile: drop the NO_INSTALL variable The last user was just removed; There is no longer any need to carry it around. Should we ever run into a need for it again, it is easy enough to revert this commit. It is unlikely, though, that we need `NO_INSTALL` again: as we saw with the just-removed item, `git-remote-testgit`, we have better locations to put executables and scripts that we do not want to install, e.g. a subdirectory in `t/`, or `contrib/`. Signed-off-by: Johannes Schindelin Signed-off-by: Junio C Hamano diff --git a/Makefile b/Makefile index 26f8ed2..f5be2f6 100644 --- a/Makefile +++ b/Makefile @@ -661,10 +661,6 @@ 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/*/ @@ -674,11 +670,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 @@ -689,9 +685,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 @@ -2683,7 +2679,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 @@ -2967,7 +2962,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)" @@ -3016,7 +3011,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/ -- cgit v0.10.2-6-g49f6 From 724d63569fe64944efd1c5a24455a0f578d33cba Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Thu, 18 Apr 2019 06:16:40 -0700 Subject: help -a: do not list commands that are excluded from the build When built with NO_CURL or with NO_UNIX_SOCKETS, some commands are skipped from the build. It does not make sense to list them in the output of `git help -a`, so let's just not. Signed-off-by: Johannes Schindelin Signed-off-by: Junio C Hamano diff --git a/Makefile b/Makefile index f5be2f6..e7bcfca 100644 --- a/Makefile +++ b/Makefile @@ -611,6 +611,7 @@ FUZZ_PROGRAMS = LIB_OBJS = PROGRAM_OBJS = PROGRAMS = +EXCLUDED_PROGRAMS = SCRIPT_PERL = SCRIPT_PYTHON = SCRIPT_SH = @@ -1319,6 +1320,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. @@ -1343,7 +1345,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" @@ -1589,7 +1595,9 @@ ifdef NO_INET_PTON LIB_OBJS += compat/inet_pton.o BASIC_CFLAGS += -DNO_INET_PTON endif -ifndef NO_UNIX_SOCKETS +ifdef NO_UNIX_SOCKETS + EXCLUDED_PROGRAMS += git-credential-cache git-credential-cache--daemon +else LIB_OBJS += unix-socket.o PROGRAM_OBJS += credential-cache.o PROGRAM_OBJS += credential-cache--daemon.o @@ -2108,7 +2116,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):\ diff --git a/generate-cmdlist.sh b/generate-cmdlist.sh index 709d674..71158f7 100755 --- a/generate-cmdlist.sh +++ b/generate-cmdlist.sh @@ -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; -- cgit v0.10.2-6-g49f6 From 7c3bd713b1f4872e4fc95397e6845b7f9e0b89a5 Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Thu, 18 Apr 2019 06:16:42 -0700 Subject: check-docs: allow command-list.txt to contain excluded commands Among other things, the `check-docs` target ensures that `command-list.txt` no longer contains commands that were dropped (or that were never added in the first place). To do so, it compares the list of commands from that file to the commands listed in `$(ALL_COMMANDS)`. However, some build options exclude commands from the latter. Fix the target to handle this situation correctly by taking the just-introduced `$(EXCLUDED_PROGRAMS)` into account. Signed-off-by: Johannes Schindelin Signed-off-by: Junio C Hamano diff --git a/Makefile b/Makefile index e7bcfca..d83104d 100644 --- a/Makefile +++ b/Makefile @@ -3089,7 +3089,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; \ -- cgit v0.10.2-6-g49f6 From faa7a096d87f188cb8bb2cc1c21f80c91817ce64 Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Thu, 18 Apr 2019 06:16:44 -0700 Subject: docs: exclude documentation for commands that have been excluded When building with certain build options, some commands are excluded from the build. For example, `git-credential-cache` is skipped when building with `NO_UNIX_SOCKETS`. Let's not build or package documentation for those excluded commands. This issue was pointed out rightfully when running `make check-docs` on Windows, where we do not yet have Unix sockets, and therefore the `credential-cache` command is excluded (yet its documentation was built and shipped). Note: building the documentation via `make -C Documentation` leaves the build system with no way to determine which commands have been excluded. If called thusly, we gracefully fail to exclude their documentation. Only when building the documentation via the top-level Makefile will it get excluded properly, or after building `Documentation/GIT-EXCLUDED-PROGRAMS` manually. Signed-off-by: Johannes Schindelin Signed-off-by: Junio C Hamano diff --git a/Documentation/.gitignore b/Documentation/.gitignore index 3ef54e0..ea27148 100644 --- a/Documentation/.gitignore +++ b/Documentation/.gitignore @@ -13,3 +13,4 @@ mergetools-*.txt manpage-base-url.xsl SubmittingPatches.txt tmp-doc-diff/ +/GIT-EXCLUDED-PROGRAMS diff --git a/Documentation/Makefile b/Documentation/Makefile index af0e2cf..e22ea2f 100644 --- a/Documentation/Makefile +++ b/Documentation/Makefile @@ -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 diff --git a/Makefile b/Makefile index d83104d..6f90cec 100644 --- a/Makefile +++ b/Makefile @@ -2451,6 +2451,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 @@ -3030,6 +3038,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/ -- cgit v0.10.2-6-g49f6 From 31cf4a6ba96c97867451bf6aeca4ea1659c69dcf Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Thu, 18 Apr 2019 06:16:46 -0700 Subject: check-docs: do not bother checking for legacy scripts' documentation In the recent years, there has been a big push to convert more and more of Git's commands that are implemented as scripts to built-ins written in pure, portable C, for robustness, speed and portability. One strategy that served us well is to convert those scripts incrementally, starting by renaming the scripts to `git-legacy-`, then introducing a built-in that does nothing else at first than checking the config setting `.useBuiltin` (which defaults to `false` at the outset) and handing off to the legacy script if so asked. Obviously, those `git-legacy-` commands share the documentation with the built-in `git-`, and are not intended to be called directly anyway. So let's not try to ensure that they are documented separately from their built-in versions. Signed-off-by: Johannes Schindelin Signed-off-by: Junio C Hamano diff --git a/Makefile b/Makefile index 6f90cec..f5fc977 100644 --- a/Makefile +++ b/Makefile @@ -3074,7 +3074,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" || \ -- cgit v0.10.2-6-g49f6 From 6ea18fffb016f7267f1f8bd2a4871500c4174f68 Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Thu, 18 Apr 2019 06:16:49 -0700 Subject: test-tool: handle the `-C ` option just like `git` In preparation for moving `git serve` into `test-tool` (because it really is only used by the test suite), we teach the `test-tool` the useful trick to change the working directory before running the test command, which will avoid introducing subshells in the test code. Signed-off-by: Johannes Schindelin Signed-off-by: Junio C Hamano diff --git a/t/helper/test-tool.c b/t/helper/test-tool.c index 99db740..2b21943 100644 --- a/t/helper/test-tool.c +++ b/t/helper/test-tool.c @@ -1,5 +1,11 @@ #include "git-compat-util.h" #include "test-tool.h" +#include "parse-options.h" + +static const char * const test_tool_usage[] = { + "test-tool [-C ] ...]]", + NULL +}; struct test_cmd { const char *name; @@ -73,11 +79,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++; -- cgit v0.10.2-6-g49f6 From b7ce24d09526d4e181920ee029c25438196c2847 Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Thu, 18 Apr 2019 06:16:51 -0700 Subject: Turn `git serve` into a test helper The `git serve` built-in was introduced in ed10cb952d31 (serve: introduce git-serve, 2018-03-15) as a backend to serve Git protocol v2, probably originally intended to be spawned by `git upload-pack`. However, in the version that the protocol v2 patches made it into core Git, `git upload-pack` calls the `serve()` function directly instead of spawning `git serve`; The only reason in life for `git serve` to survive as a built-in command is to provide a way to test the protocol v2 functionality. Meaning that it does not even have to be a built-in that is installed with end-user facing Git installations, but it can be a test helper instead. Let's make it so. Signed-off-by: Johannes Schindelin Signed-off-by: Junio C Hamano diff --git a/Makefile b/Makefile index f5fc977..9ce62fa 100644 --- a/Makefile +++ b/Makefile @@ -758,6 +758,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 @@ -1127,7 +1128,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 diff --git a/builtin.h b/builtin.h index 6538932..c48636e 100644 --- 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 index d3fd240..0000000 --- a/builtin/serve.c +++ /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 []"), - 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; -} diff --git a/git.c b/git.c index 2dd5886..c58b067 100644 --- a/git.c +++ b/git.c @@ -548,7 +548,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 index 0000000..aee35e5 --- /dev/null +++ b/t/helper/test-serve-v2.c @@ -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 []"), + 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; +} diff --git a/t/helper/test-tool.c b/t/helper/test-tool.c index 2b21943..4bf3666 100644 --- a/t/helper/test-tool.c +++ b/t/helper/test-tool.c @@ -48,6 +48,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 }, diff --git a/t/helper/test-tool.h b/t/helper/test-tool.h index 25abed1..bc72370 100644 --- a/t/helper/test-tool.h +++ b/t/helper/test-tool.h @@ -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); diff --git a/t/t5701-git-serve.sh b/t/t5701-git-serve.sh index fe45bf8..ffb9613 100755 --- a/t/t5701-git-serve.sh +++ b/t/t5701-git-serve.sh @@ -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 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 out 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 err err err err err out && + test-tool serve-v2 --stateless-rpc out && test-tool pkt-line unpack actual && test_cmp expect actual ' @@ -107,7 +108,7 @@ test_expect_success 'basic ref-prefixes' ' 0000 EOF - git serve --stateless-rpc out && + test-tool serve-v2 --stateless-rpc out && test-tool pkt-line unpack actual && test_cmp expect actual ' @@ -127,7 +128,7 @@ test_expect_success 'refs/heads prefix' ' 0000 EOF - git serve --stateless-rpc out && + test-tool serve-v2 --stateless-rpc out && test-tool pkt-line unpack actual && test_cmp expect actual ' @@ -148,7 +149,7 @@ test_expect_success 'peel parameter' ' 0000 EOF - git serve --stateless-rpc out && + test-tool serve-v2 --stateless-rpc out && test-tool pkt-line unpack actual && test_cmp expect actual ' @@ -169,7 +170,7 @@ test_expect_success 'symrefs parameter' ' 0000 EOF - git serve --stateless-rpc out && + test-tool serve-v2 --stateless-rpc out && test-tool pkt-line unpack actual && test_cmp expect actual ' @@ -189,7 +190,7 @@ test_expect_success 'sending server-options' ' 0000 EOF - git serve --stateless-rpc out && + test-tool serve-v2 --stateless-rpc out && test-tool pkt-line unpack 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 /dev/null 2>err && + ( + cd server && + test_must_fail test-tool serve-v2 --stateless-rpc + ) /dev/null 2>err && grep "unexpected line: .this-is-not-a-command." err ' diff --git a/t/t5702-protocol-v2.sh b/t/t5702-protocol-v2.sh index db4ae09..8691bfc 100755 --- a/t/t5702-protocol-v2.sh +++ b/t/t5702-protocol-v2.sh @@ -359,12 +359,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 /dev/null 2>err && + test_must_fail test-tool -C server serve-v2 --stateless-rpc \ + /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 /dev/null + test-tool -C server serve-v2 --stateless-rpc /dev/null ' test_expect_success 'default refspec is used to filter ref when fetchcing' ' diff --git a/t/t5703-upload-pack-ref-in-want.sh b/t/t5703-upload-pack-ref-in-want.sh index f87b2f6..dd1cbd0 100755 --- a/t/t5703-upload-pack-ref-in-want.sh +++ b/t/t5703-upload-pack-ref-in-want.sh @@ -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 out out out out out out out out out