]> git.ipfire.org Git - thirdparty/git.git/commitdiff
Merge branch 'mb/config-document-include' into maint
authorJunio C Hamano <gitster@pobox.com>
Fri, 5 Aug 2022 22:51:36 +0000 (15:51 -0700)
committerJunio C Hamano <gitster@pobox.com>
Fri, 5 Aug 2022 22:51:36 +0000 (15:51 -0700)
Add missing documentation for "include" and "includeIf" features in
"git config" file format, which incidentally teaches the command
line completion to include them in its offerings.
source: <pull.1285.v2.git.1658002423864.gitgitgadget@gmail.com>

* mb/config-document-include:
  config.txt: document include, includeIf

1  2 
Documentation/config.txt
t/t9902-completion.sh

diff --combined Documentation/config.txt
index e376d547ce044c4d103877f646b11cc70ad6422a,12a89f693597eab37266dac44c0fc4c68033e3a6..5b5b9765699933c406af47f6c1b4ee9ed885f0ba
@@@ -159,33 -159,6 +159,33 @@@ all branches that begin with `foo/`. Th
  organized hierarchically and you would like to apply a configuration to
  all the branches in that hierarchy.
  
 +`hasconfig:remote.*.url:`::
 +      The data that follows this keyword is taken to
 +      be a pattern with standard globbing wildcards and two
 +      additional ones, `**/` and `/**`, that can match multiple
 +      components. The first time this keyword is seen, the rest of
 +      the config files will be scanned for remote URLs (without
 +      applying any values). If there exists at least one remote URL
 +      that matches this pattern, the include condition is met.
 ++
 +Files included by this option (directly or indirectly) are not allowed
 +to contain remote URLs.
 ++
 +Note that unlike other includeIf conditions, resolving this condition
 +relies on information that is not yet known at the point of reading the
 +condition. A typical use case is this option being present as a
 +system-level or global-level config, and the remote URL being in a
 +local-level config; hence the need to scan ahead when resolving this
 +condition. In order to avoid the chicken-and-egg problem in which
 +potentially-included files can affect whether such files are potentially
 +included, Git breaks the cycle by prohibiting these files from affecting
 +the resolution of these conditions (thus, prohibiting them from
 +declaring remote URLs).
 ++
 +As for the naming of this keyword, it is for forwards compatibiliy with
 +a naming scheme that supports more variable-based include conditions,
 +but currently Git only supports the exact keyword described above.
 +
  A few more notes on matching via `gitdir` and `gitdir/i`:
  
   * Symlinks in `$GIT_DIR` are not resolved before matching.
@@@ -253,14 -226,6 +253,14 @@@ Exampl
  ; currently checked out
  [includeIf "onbranch:foo-branch"]
        path = foo.inc
 +
 +; include only if a remote with the given URL exists (note
 +; that such a URL may be provided later in a file or in a
 +; file read after this file is read, as seen in this example)
 +[includeIf "hasconfig:remote.*.url:https://example.com/**"]
 +      path = foo.inc
 +[remote "origin"]
 +      url = https://example.com/git
  ----
  
  Values
@@@ -445,6 -410,8 +445,8 @@@ include::config/i18n.txt[
  
  include::config/imap.txt[]
  
+ include::config/includeif.txt[]
  include::config/index.txt[]
  
  include::config/init.txt[]
@@@ -495,7 -462,7 +497,7 @@@ include::config/repack.txt[
  
  include::config/rerere.txt[]
  
 -include::config/reset.txt[]
 +include::config/revert.txt[]
  
  include::config/safe.txt[]
  
@@@ -505,8 -472,6 +507,8 @@@ include::config/sequencer.txt[
  
  include::config/showbranch.txt[]
  
 +include::config/sparse.txt[]
 +
  include::config/splitindex.txt[]
  
  include::config/ssh.txt[]
diff --combined t/t9902-completion.sh
index 31526e6b64156852a5d5d528c505dd17a16a8c34,80cc11e7ecdbadd69e505991518b30ef1a6fd31b..43de868b8005d330c10ec5d81fcacdc325aff858
@@@ -1444,161 -1444,6 +1444,161 @@@ test_expect_success 'git checkout - wit
        EOF
  '
  
 +test_expect_success 'setup sparse-checkout tests' '
 +      # set up sparse-checkout repo
 +      git init sparse-checkout &&
 +      (
 +              cd sparse-checkout &&
 +              mkdir -p folder1/0/1 folder2/0 folder3 &&
 +              touch folder1/0/1/t.txt &&
 +              touch folder2/0/t.txt &&
 +              touch folder3/t.txt &&
 +              git add . &&
 +              git commit -am "Initial commit"
 +      )
 +'
 +
 +test_expect_success 'sparse-checkout completes subcommands' '
 +      test_completion "git sparse-checkout " <<-\EOF
 +      list Z
 +      init Z
 +      set Z
 +      add Z
 +      reapply Z
 +      disable Z
 +      EOF
 +'
 +
 +test_expect_success 'cone mode sparse-checkout completes directory names' '
 +      # initialize sparse-checkout definitions
 +      git -C sparse-checkout sparse-checkout set --cone folder1/0 folder3 &&
 +
 +      # test tab completion
 +      (
 +              cd sparse-checkout &&
 +              test_completion "git sparse-checkout set f" <<-\EOF
 +              folder1/
 +              folder2/
 +              folder3/
 +              EOF
 +      ) &&
 +
 +      (
 +              cd sparse-checkout &&
 +              test_completion "git sparse-checkout set folder1/" <<-\EOF
 +              folder1/0/
 +              EOF
 +      ) &&
 +
 +      (
 +              cd sparse-checkout &&
 +              test_completion "git sparse-checkout set folder1/0/" <<-\EOF
 +              folder1/0/1/
 +              EOF
 +      ) &&
 +
 +      (
 +              cd sparse-checkout/folder1 &&
 +              test_completion "git sparse-checkout add 0" <<-\EOF
 +              0/
 +              EOF
 +      )
 +'
 +
 +test_expect_success 'cone mode sparse-checkout completes directory names with spaces and accents' '
 +      # reset sparse-checkout
 +      git -C sparse-checkout sparse-checkout disable &&
 +      (
 +              cd sparse-checkout &&
 +              mkdir "directory with spaces" &&
 +              mkdir "directory-with-áccent" &&
 +              >"directory with spaces/randomfile" &&
 +              >"directory-with-áccent/randomfile" &&
 +              git add . &&
 +              git commit -m "Add directory with spaces and directory with accent" &&
 +              git sparse-checkout set --cone "directory with spaces" \
 +                      "directory-with-áccent" &&
 +              test_completion "git sparse-checkout add dir" <<-\EOF &&
 +              directory with spaces/
 +              directory-with-áccent/
 +              EOF
 +              rm -rf "directory with spaces" &&
 +              rm -rf "directory-with-áccent" &&
 +              git add . &&
 +              git commit -m "Remove directory with spaces and directory with accent"
 +      )
 +'
 +
 +# use FUNNYNAMES to avoid running on Windows, which doesn't permit tabs in paths
 +test_expect_success FUNNYNAMES 'cone mode sparse-checkout completes directory names with tabs' '
 +      # reset sparse-checkout
 +      git -C sparse-checkout sparse-checkout disable &&
 +      (
 +              cd sparse-checkout &&
 +              mkdir "$(printf "directory\twith\ttabs")" &&
 +              >"$(printf "directory\twith\ttabs")/randomfile" &&
 +              git add . &&
 +              git commit -m "Add directory with tabs" &&
 +              git sparse-checkout set --cone \
 +                      "$(printf "directory\twith\ttabs")" &&
 +              test_completion "git sparse-checkout add dir" <<-\EOF &&
 +              directory       with    tabs/
 +              EOF
 +              rm -rf "$(printf "directory\twith\ttabs")" &&
 +              git add . &&
 +              git commit -m "Remove directory with tabs"
 +      )
 +'
 +
 +# use FUNNYNAMES to avoid running on Windows, and !CYGWIN for Cygwin, as neither permit backslashes in paths
 +test_expect_success FUNNYNAMES,!CYGWIN 'cone mode sparse-checkout completes directory names with backslashes' '
 +      # reset sparse-checkout
 +      git -C sparse-checkout sparse-checkout disable &&
 +      (
 +              cd sparse-checkout &&
 +              mkdir "directory\with\backslashes" &&
 +              >"directory\with\backslashes/randomfile" &&
 +              git add . &&
 +              git commit -m "Add directory with backslashes" &&
 +              git sparse-checkout set --cone \
 +                      "directory\with\backslashes" &&
 +              test_completion "git sparse-checkout add dir" <<-\EOF &&
 +              directory\with\backslashes/
 +              EOF
 +              rm -rf "directory\with\backslashes" &&
 +              git add . &&
 +              git commit -m "Remove directory with backslashes"
 +      )
 +'
 +
 +test_expect_success 'non-cone mode sparse-checkout uses bash completion' '
 +      # reset sparse-checkout repo to non-cone mode
 +      git -C sparse-checkout sparse-checkout disable &&
 +      git -C sparse-checkout sparse-checkout set --no-cone &&
 +
 +      (
 +              cd sparse-checkout &&
 +              # expected to be empty since we have not configured
 +              # custom completion for non-cone mode
 +              test_completion "git sparse-checkout set f" <<-\EOF
 +
 +              EOF
 +      )
 +'
 +
 +test_expect_success 'git sparse-checkout set --cone completes directory names' '
 +      git -C sparse-checkout sparse-checkout disable &&
 +
 +      (
 +              cd sparse-checkout &&
 +              test_completion "git sparse-checkout set --cone f" <<-\EOF
 +              folder1/
 +              folder2/
 +              folder3/
 +              EOF
 +      )
 +'
 +
  test_expect_success 'git switch - with -d, complete all references' '
        test_completion "git switch -d " <<-\EOF
        HEAD Z
@@@ -2485,6 -2330,13 +2485,13 @@@ test_expect_success 'git config - secti
        EOF
  '
  
+ test_expect_success 'git config - section include, includeIf' '
+       test_completion "git config inclu" <<-\EOF
+       include.Z
+       includeIf.Z
+       EOF
+ '
  test_expect_success 'git config - variable name' '
        test_completion "git config log.d" <<-\EOF
        log.date Z
        EOF
  '
  
+ test_expect_success 'git config - variable name include' '
+       test_completion "git config include.p" <<-\EOF
+       include.path Z
+       EOF
+ '
  test_expect_success 'git config - value' '
        test_completion "git config color.pager " <<-\EOF
        false Z
@@@ -2551,33 -2409,27 +2564,33 @@@ test_expect_success 'options with value
  '
  
  test_expect_success 'sourcing the completion script clears cached commands' '
 -      __git_compute_all_commands &&
 -      verbose test -n "$__git_all_commands" &&
 -      . "$GIT_BUILD_DIR/contrib/completion/git-completion.bash" &&
 -      verbose test -z "$__git_all_commands"
 +      (
 +              __git_compute_all_commands &&
 +              verbose test -n "$__git_all_commands" &&
 +              . "$GIT_BUILD_DIR/contrib/completion/git-completion.bash" &&
 +              verbose test -z "$__git_all_commands"
 +      )
  '
  
  test_expect_success 'sourcing the completion script clears cached merge strategies' '
 -      __git_compute_merge_strategies &&
 -      verbose test -n "$__git_merge_strategies" &&
 -      . "$GIT_BUILD_DIR/contrib/completion/git-completion.bash" &&
 -      verbose test -z "$__git_merge_strategies"
 +      (
 +              __git_compute_merge_strategies &&
 +              verbose test -n "$__git_merge_strategies" &&
 +              . "$GIT_BUILD_DIR/contrib/completion/git-completion.bash" &&
 +              verbose test -z "$__git_merge_strategies"
 +      )
  '
  
  test_expect_success 'sourcing the completion script clears cached --options' '
 -      __gitcomp_builtin checkout &&
 -      verbose test -n "$__gitcomp_builtin_checkout" &&
 -      __gitcomp_builtin notes_edit &&
 -      verbose test -n "$__gitcomp_builtin_notes_edit" &&
 -      . "$GIT_BUILD_DIR/contrib/completion/git-completion.bash" &&
 -      verbose test -z "$__gitcomp_builtin_checkout" &&
 -      verbose test -z "$__gitcomp_builtin_notes_edit"
 +      (
 +              __gitcomp_builtin checkout &&
 +              verbose test -n "$__gitcomp_builtin_checkout" &&
 +              __gitcomp_builtin notes_edit &&
 +              verbose test -n "$__gitcomp_builtin_notes_edit" &&
 +              . "$GIT_BUILD_DIR/contrib/completion/git-completion.bash" &&
 +              verbose test -z "$__gitcomp_builtin_checkout" &&
 +              verbose test -z "$__gitcomp_builtin_notes_edit"
 +      )
  '
  
  test_expect_success 'option aliases are not shown by default' '
  '
  
  test_expect_success 'option aliases are shown with GIT_COMPLETION_SHOW_ALL' '
 -      . "$GIT_BUILD_DIR/contrib/completion/git-completion.bash" &&
 -      GIT_COMPLETION_SHOW_ALL=1 && export GIT_COMPLETION_SHOW_ALL &&
 -      test_completion "git clone --recurs" <<-\EOF
 -      --recurse-submodules Z
 -      --recursive Z
 -      EOF
 +      (
 +              . "$GIT_BUILD_DIR/contrib/completion/git-completion.bash" &&
 +              GIT_COMPLETION_SHOW_ALL=1 && export GIT_COMPLETION_SHOW_ALL &&
 +              test_completion "git clone --recurs" <<-\EOF
 +              --recurse-submodules Z
 +              --recursive Z
 +              EOF
 +      )
 +'
 +
 +test_expect_success 'plumbing commands are excluded without GIT_COMPLETION_SHOW_ALL_COMMANDS' '
 +      (
 +              . "$GIT_BUILD_DIR/contrib/completion/git-completion.bash" &&
 +              sane_unset GIT_TESTING_PORCELAIN_COMMAND_LIST &&
 +
 +              # Just mainporcelain, not plumbing commands
 +              run_completion "git c" &&
 +              grep checkout out &&
 +              ! grep cat-file out
 +      )
 +'
 +
 +test_expect_success 'all commands are shown with GIT_COMPLETION_SHOW_ALL_COMMANDS (also main non-builtin)' '
 +      (
 +              . "$GIT_BUILD_DIR/contrib/completion/git-completion.bash" &&
 +              GIT_COMPLETION_SHOW_ALL_COMMANDS=1 &&
 +              export GIT_COMPLETION_SHOW_ALL_COMMANDS &&
 +              sane_unset GIT_TESTING_PORCELAIN_COMMAND_LIST &&
 +
 +              # Both mainporcelain and plumbing commands
 +              run_completion "git c" &&
 +              grep checkout out &&
 +              grep cat-file out &&
 +
 +              # Check "gitk", a "main" command, but not a built-in + more plumbing
 +              run_completion "git g" &&
 +              grep gitk out &&
 +              grep get-tar-commit-id out
 +      )
  '
  
  test_expect_success '__git_complete' '