1. 09 10月, 2020 1 次提交
    • D
      checkout: learn to respect checkout.guess · 64f1f58f
      Denton Liu 提交于
      The current behavior of git checkout/switch is that --guess is currently
      enabled by default. However, some users may not wish for this to happen
      automatically. Instead of forcing users to specify --no-guess manually
      each time, teach these commands the checkout.guess configuration
      variable that gives users the option to set a default behavior.
      
      Teach the completion script to recognize the new config variable and
      disable DWIM logic if it is set to false.
      Signed-off-by: NDenton Liu <liu.denton@gmail.com>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      64f1f58f
  2. 27 9月, 2020 1 次提交
  3. 26 6月, 2020 1 次提交
  4. 29 5月, 2020 13 次提交
    • J
      completion: improve handling of --orphan option of switch/checkout · 91439928
      Jacob Keller 提交于
      The --orphan option is used to create a local branch which is detached
      from the current history. In git switch, it always resets to the empty
      tree, and thus the only completion we can provide is a branch name.
      Follow the same rules for -c/-C (and -b/-B) when completing the argument
      to --orphan.
      
      In the case of git switch, after we complete the argument, there is
      nothing more we can complete for git switch, so do not even try. Nothing
      else would be valid.
      
      In the case of git checkout, --orphan takes a start point which it uses
      to determine the checked out tree, even though it created orphaned
      history.
      
      Update the previously added test cases as they are now passing.
      Signed-off-by: NJacob Keller <jacob.keller@gmail.com>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      91439928
    • J
      completion: improve handling of -c/-C and -b/-B in switch/checkout · acb658fe
      Jacob Keller 提交于
      A previous commit added several test cases highlighting the subpar
      completion logic for -c/-C and -b/-B when completing git switch and git
      checkout.
      
      In order to distinguish completing the argument vs the start-point for
      this option, we now use the wordlist to determine the previous full word
      on the command line.
      
      If it's -c or -C (-b/-B for checkout), then we know that we are
      completing the argument for the branch name.
      
      Given that a user who already knows the branch name they want to
      complete will simply not use completion, it makes sense to complete the
      small subset of local branches when completing the argument for -c/-C.
      
      In all other cases, if -c/-C are on the command line but are not the
      most recent option, then we must be completing a start-point, and should
      allow completing against all references.
      
      Update the -c/-C and -b/-B tests to indicate they now pass.
      Signed-off-by: NJacob Keller <jacob.keller@gmail.com>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      acb658fe
    • J
      completion: improve handling of --track in switch/checkout · 00e7bd2b
      Jacob Keller 提交于
      Current completion for the --track option of git switch and git checkout
      is sub par. In addition to the DWIM logic of a bare branch name, --track
      has DWIM logic to convert specified remote/branch names into a local
      branch tracking that remote. For example
      
        $git switch --track origin/master
      
      This will create a local branch name master, that tracks the master
      branch of the origin remote.
      
      In fact, git switch --track on its own will not accept other forms of
      references. These must instead be specified manually via the -c/-C/-b/-B
      options.
      
      Introduce __git_remote_heads() and the "remote-heads" mode for
      __git_complete_refs. Use this when the --track option is provided while
      completing in _git_switch and _git_checkout. Just as in the --detach
      case, we never enable DWIM mode for --track, because it doesn't make
      sense.
      
      It should be noted that completion support is still a bit sub par when
      it comes to handling -c/-C and --orphan. This will be resolved in
      a future change.
      Signed-off-by: NJacob Keller <jacob.keller@gmail.com>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      00e7bd2b
    • J
      completion: improve handling of --detach in checkout · 6d76a5cc
      Jacob Keller 提交于
      Just like git switch, we should not complete DWIM remote branch names
      if --detach has been specified. To avoid this, refactor _git_checkout in
      a similar way to _git_switch.
      
      Note that we don't simply clear dwim_opt when we find -d or --detach, as
      we will be adding other modes and checks, making this flow easier to
      follow.
      
      Update the previously failing tests to show that the breakage has been
      resolved.
      Signed-off-by: NJacob Keller <jacob.keller@gmail.com>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      6d76a5cc
    • J
      completion: improve completion for git switch with no options · 68d97c7f
      Jacob Keller 提交于
      Add a new --mode option to __git_complete_refs, which allows changing
      the behavior to call __git_heads instead of __git_refs.
      
      By passing --mode=heads, __git_complete_refs will only output local
      branches. This enables using "--mode=heads --dwim" to enable listing
      local branches and the remote unique branch names for DWIM.
      
      Refactor completion support to use the new mode option, rather than
      calling __git_heads directly. This has the advantage that we can now
      correctly allow local branches along with suitable DWIM refs, rather
      than only allowing DWIM when we complete all references.
      
      Choose what mode it uses when calling __git_complete_refs. If -d or
      --detach have been provided, then simply complete all refs, but
      *without* the DWIM option as these DWIM names won't work properly in
      --detach mode.
      
      Otherwise, call __git_complete_refs with the default dwim_opt value and
      use the new "heads" mode.
      
      In this way, the basic support for completing just "git switch <TAB>"
      will result in only local branches and remote unique names for DWIM.
      
      The basic no-options tests for git switch, as well as several of the
      -c/-C tests now pass, so remove the known breakage tags.
      Signed-off-by: NJacob Keller <jacob.keller@gmail.com>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      68d97c7f
    • J
      completion: improve handling of DWIM mode for switch/checkout · 4e79adf4
      Jacob Keller 提交于
      A new helper, __git_find_last_on_cmdline is introduced, similar to the
      already existing __git_find_on_cmdline, but which operates in reverse,
      finding the *last* matching word of the provided wordlist.
      
      Use this in a new __git_checkout_default_dwim_mode() function that will
      determine when to enable listing of DWIM remote branches.
      
      The __git_find_last_on_cmdline() function is used to determine which
      --guess or --no-guess is in effect. If either one is provided, then we
      unconditionally enable or disable the DWIM mode based on the last
      provided option.
      
      If neither --guess nor --no-guess is provided, then we check for
      --no-track, and finally for GIT_COMPLETION_CHECKOUT_NO_GUESS=1.
      
      This function is then used in _git_switch and _git_checkout to improve
      the handling for when we enable listing of these DWIM remote branches.
      
      This new logic is more robust, as we will correctly identify superseded
      options, and ensure that both _git_switch and _git_checkout enable DWIM
      in similar ways.
      
      We can now update a few tests to indicate they pass. A few of the tests
      previously added to highlight issues with the old DWIM logic still fail.
      This is because of a separate issue related to the default completion
      behavior of git switch, which will be addressed in a future change.
      
      Additionally, due to this change, a few tests for the -b/-B handling of
      git checkout now fail. This is a minor regression, and will be fixed by
      a following change that improves the overall handling of -b/-B. Mark
      these tests as known breakages for now.
      Signed-off-by: NJacob Keller <jacob.keller@gmail.com>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      4e79adf4
    • J
      completion: add tests showing subpar switch/checkout --orphan logic · c81ca56b
      Jacob Keller 提交于
      Similar to -c/-C, --orphan takes an argument which is the branch name to
      use. We ought to complete this branch name using similar rules as to how
      we complete new branch names for -c/-C and -b/-B. Namely, limit the
      total number of options provided by completing to the local branches.
      
      Additionally, git switch --orphan does not take any start point and will
      always create using the empty-tree. Thus, after the branch name is
      completed, git switch --orphan should not complete any references.
      
      Add test cases showing the expected behavior of --orphan, for both the
      argument and starting point.
      Signed-off-by: NJacob Keller <jacob.keller@gmail.com>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      c81ca56b
    • J
      completion: add tests showing subpar -c/C argument completion · 7f59d604
      Jacob Keller 提交于
      When using the branch creation argument for git switch or git checkout
      (-c/-C or -b/-B), the commands switch to a different mode: `git switch
      -c <branch> <some-referance>` means to create a branch named <branch> at
      the commit referred to by <some-reference>.
      
      When completing git switch or git checkout, it makes sense to complete
      the branch name differently from the start point.
      
      When completing a branch, one might consider that we do not have
      anything worth completing. After all, a new branch must have an entirely
      new name. Consider, however, that if a user names branches using some
      similar scheme, they might wish to name a new branch by modifying the
      name of an existing branch.
      
      To avoid overloading completion for the argument, it seems reasonable to
      complete only the local branch names and the valid "Do What I Mean"
      remote branch names.
      
      Add tests for the completion of the argument to -c/-C and -b/-B,
      highlighting this preferred completion behavior.
      Signed-off-by: NJacob Keller <jacob.keller@gmail.com>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      7f59d604
    • J
      completion: add tests showing subpar -c/-C startpoint completion · b07d77a2
      Jacob Keller 提交于
      When using the branch creation argument for git switch or git checkout,
      -c/-C or -b/-B, the commands operate in a different mode: `git switch -c
      <branch> <some-reference>` means to create a branch named <branch> at
      the commit referred to by <some-reference>.
      
      When completing the start-point, we ought to always complete all valid
      references.
      
      Add tests for the completion of the start-point to -c/-C and -b/-B.
      Signed-off-by: NJacob Keller <jacob.keller@gmail.com>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      b07d77a2
    • J
      completion: add tests showing subpar switch/checkout --track logic · c55b99c3
      Jacob Keller 提交于
      When the --track option is provided to git switch or git checkout, and
      no branch is specified by -c or -b, git will interpret the tracking
      branch to determine the local branch name to use. This "Do What I Mean"
      logic is similar but distinct from the default DWIM logic of
      interpreting a unique remote branch name as a request to create and
      track that branch.
      
      For example, `git switch --track origin/master` is interpreted as
      a request to create a local branch named master that is tracking
      origin/master.
      
      The current completion for git checkout in this regard is only somewhat
      poor:
      
       $git checkout --track <TAB>
       HEAD
       master
       matching-branch
       matching-tag
       other/branch-in-other
       other/master-in-other
      
      At least it still includes remote references. The clutter from including
      all references isn't too bad.
      
      However, git switch completion is terrible:
      
       $git switch --track <TAB>
       master
       matching-branch
      
      It only shows local branches, not even allowing any form of completion
      of the remote references!
      
      Add tests which highlight the expected behavior of completing --track on
      its own.
      
      Note that when -c/-C or -b/-B are provided we do expect completing more
      references, but this will be discussed in a future change that addresses
      these options specifically.
      Signed-off-by: NJacob Keller <jacob.keller@gmail.com>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      c55b99c3
    • J
      completion: add tests showing subar checkout --detach logic · e69fb0a1
      Jacob Keller 提交于
      When completing words for git switch, the completion function correctly
      disables the DWIM remote branch names when in the '--detach' mode. These
      DWIM remote branch names will not work when the --detach option is
      specified, so it does not make sense to complete them.
      
      git checkout, however, does not disable the completion of DWIM remote
      branch names in this case.
      
      Add test cases for both git switch and git checkout showing the expected
      behavior.
      Signed-off-by: NJacob Keller <jacob.keller@gmail.com>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      e69fb0a1
    • J
      completion: add tests showing subpar DWIM logic for switch/checkout · ab58e90f
      Jacob Keller 提交于
      When provided with a single argument that is the name of a remote branch
      that does not yet exist locally, both git switch and git checkout can
      interpret this as a request to create a local branch that tracks that
      remote branch. We call this behavior "Do What I Mean", or DWIM for
      short.
      
      To aid in using this DWIM, it makes sense for completion to list these
      unique remote branch names when completing possible arguments for git
      switch and git checkout. Indeed, both _git_checkout and _git_switch
      implement support for completing such DWIM branch names.
      
      In other words, in addition to the usual completions provided for git
      switch, this "DWIM" logic means completion will include the names of
      branches on remotes that are unique and thus there can be no ambiguity
      of which remote to track when creating the local branch.
      
      However, the DWIM logic is not always active. Many options, such as
      --no-guess, --no-track, and --track disable this DWIM logic, as they
      cause git switch and git checkout to behave in different modes.
      
      Additionally, some completion users do not wish to have tab completion
      include these remote names by default, and thus introduced
      GIT_COMPLETION_CHECKOUT_NO_GUESS as an optional way to configure the
      completion support to disable this feature of completion support.
      
      For this reason, _git_checkout and _git_switch have many rules about
      when to enable or disable completing of these remote refs. The two
      commands follow similar but not identical rules.
      
      Set aside the question of command modes that do not accept this DWIM
      logic (--track, -c, --orphan, --detach) for now. Thinking just about the
      main mode of git checkout and git switch, the following guidelines will
      help explain the basic rules we ought to support when deciding whether
      to list the remote branches for DWIM in completion.
      
      1.  if --guess is enabled, we should list DWIM remote branch names, even
          if something else would disable it
      2.  if --no-guess, --no-track or GIT_COMPLETION_CHECKOUT_NO_GUESS=1,
          then we should disable listing DWIM remote branch names.
      3.  Since the '--guess' option is a boolean option, a later --guess
          should override --no-guess, and a later --no-guess should override
          --guess.
      
      Putting all of these together, add some tests that highlight the
      expected behavior of this DWIM logic.
      Signed-off-by: NJacob Keller <jacob.keller@gmail.com>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      ab58e90f
    • J
      completion: add test showing subpar git switch completion · fab466f9
      Jacob Keller 提交于
      When provided with no options, git switch only allows switching between
      branches. The one exception to this is the "Do What I Mean" logic that
      allows a unique remote branch name to be interpreted as a request to
      create a branch of the same name that is tracking that remote branch.
      
      Unfortunately, the logic for the completion of git switch results in
      completing not just branch names, but also pseudorefs like HEAD, tags,
      and fully specified <remote>/<branch> references.
      
      For example, we currently complete the following:
      
       $git switch <TAB>
       HEAD
       branch-in-other
       master
       master-in-other
       matching-branch
       matching-tag
       other/branch-in-other
       other/master-in-other
      
      Indeed, if one were to attempt to use git switch with some of these
      provided options, git will reject the request:
      
       $git switch HEAD
       fatal: a branch is expected, got 'HEAD
      
       $git switch matching-tag
       fatal: a branch is expected, got tag 'matching-tag'
      
       $git switch other/branch-in-other
       fatal: a branch is expected, got remote branch 'other/branch-in-other'
      
      Ideally, git switch without options ought to complete only words which
      will be accepted. Without options, this means to list local branch names
      and the unique remote branch names without their remote name pre-pended.
      
       $git switch <TAB>
       branch-in-other
       master
       master-in-other
       matching-branch
      
      Add a test case that highlights this subpar completion. Also add
      a similar test for git checkout completion that shows that due to the
      complex nature of git checkout, it must complete all references.
      Signed-off-by: NJacob Keller <jacob.keller@gmail.com>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      fab466f9
  5. 02 4月, 2020 1 次提交
    • E
      completion: fix 'git add' on paths under an untracked directory · c0af173a
      Elijah Newren 提交于
      As reported on the git mailing list, since git-2.25,
          git add untracked-dir/
      has been tab completing to
          git add untracked-dir/./
      
      The cause for this was that with commit b9670c1f (dir: fix checks on
      common prefix directory, 2019-12-19),
          git ls-files -o --directory untracked-dir/
      (or the equivalent `git -C untracked-dir ls-files -o --directory`) began
      reporting
          untracked-dir/
      instead of listing paths underneath that directory.  It may also be
      worth noting that the real command in question was
          git -C untracked-dir ls-files -o --directory '*'
      which is equivalent to
          git ls-files -o --directory 'untracked-dir/*'
      which behaves the same for the purposes of this issue (the '*' can match
      the empty string), but becomes relevant for the proposed fix.
      
      At first, based on the report, I decided to try to view this as a
      regression and tried to find a way to recover the old behavior without
      breaking other stuff, or at least breaking as little as possible.
      However, in the end, I couldn't figure out a way to do it that wouldn't
      just cause lots more problems than it solved.  The old behavior was a
      bug:
        * Although older git would avoid cleaning anything with `git clean -f
          .git`, it would wipe out everything under that direcotry with `git
          clean -f .git/`.  Despite the difference in command used, this is
          relevant because the exact same change that fixed clean changed the
          behavior of ls-files.
        * Older git would report different results based solely on presence or
          absence of a trailing slash for $SUBDIR in the command `git ls-files
          -o --directory $SUBDIR`.
        * Older git violated the documented behavior of not recursing into
          directories that matched the pathspec when --directory was
          specified.
        * And, after all, commit b9670c1f (dir: fix checks on common prefix
          directory, 2019-12-19) didn't overlook this issue; it explicitly
          stated that the behavior of the command was being changed to bring
          it inline with the docs.
      
      (Also, if it helps, despite that commit being merged during the 2.25
      series, this bug was not reported during the 2.25 cycle, nor even during
      most of the 2.26 cycle -- it was reported a day before 2.26 was
      released.  So the impact of the change is at least somewhat small.)
      
      Instead of relying on a bug of ls-files in reporting the wrong content,
      change the invocation of ls-files used by git-completion to make it grab
      paths one depth deeper.  Do this by changing '$DIR/*' (match $DIR/ plus
      0 or more characters) into '$DIR/?*' (match $DIR/ plus 1 or more
      characters).  Note that the '?' character should not be added when
      trying to complete a filename (e.g. 'git ls-files -o --directory
      "merge.c?*"' would not correctly return "merge.c" when such a file
      exists), so we have to make sure to add the '?' character only in cases
      where the path specified so far is a directory.
      Signed-off-by: NElijah Newren <newren@gmail.com>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      c0af173a
  6. 16 1月, 2020 2 次提交
  7. 05 12月, 2019 1 次提交
  8. 10 11月, 2019 2 次提交
  9. 16 10月, 2019 1 次提交
    • D
      format-patch: teach --cover-from-description option · bf8e65b3
      Denton Liu 提交于
      Before, when format-patch generated a cover letter, only the body would
      be populated with a branch's description while the subject would be
      populated with placeholder text. However, users may want to have the
      subject of their cover letter automatically populated in the same way.
      
      Teach format-patch to accept the `--cover-from-description` option and
      corresponding `format.coverFromDescription` config, allowing users to
      populate different parts of the cover letter (including the subject
      now).
      Signed-off-by: NDenton Liu <liu.denton@gmail.com>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      bf8e65b3
  10. 06 9月, 2019 1 次提交
  11. 14 8月, 2019 5 次提交
    • S
      completion: complete config variables and values for 'git clone --config=' · 5af9d5f6
      SZEDER Gábor 提交于
      Completing configuration sections and variable names for the stuck
      argument of 'git clone --config=<TAB>' requires a bit of extra care
      compared to doing the same for the unstuck argument of 'git clone
      --config <TAB>', because we have to deal with that '--config=' being
      part of the current word to be completed.
      
      Add an option to the __git_complete_config_variable_name_and_value()
      and in turn to the __git_complete_config_variable_name() helper
      functions to specify the current section/variable name to be
      completed, so they can be used even when completing the stuck argument
      of '--config='.
      
      __git_complete_config_variable_value() already has such an option, and
      thus no further changes were necessary to complete possible values
      after 'git clone --config=section.name=<TAB>'.
      Signed-off-by: NSZEDER Gábor <szeder.dev@gmail.com>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      5af9d5f6
    • S
      completion: complete values of configuration variables after 'git -c var=' · dd334728
      SZEDER Gábor 提交于
      'git config' expects a configuration variable's name and value in
      separate options, so we complete values as they stand on their own on
      the command line.  'git -c', however, expects them in a single option
      joined by a '=' character, so we should be able to complete values
      when they are following 'section.name=' in the same word.
      
      Add new options to the __git_complete_config_variable_value() function
      to allow callers to specify the current word to be completed and the
      configuration variable whose value is to be completed, and use these
      to complete possible values after 'git -c 'section.name=<TAB>'.
      Signed-off-by: NSZEDER Gábor <szeder.dev@gmail.com>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      dd334728
    • S
      completion: complete configuration sections and variable names for 'git -c' · e1e00089
      SZEDER Gábor 提交于
      'git config' expects a configuration variable's name and value in
      separate arguments, so we let the __gitcomp() helper append a space
      character to each variable name by default, like we do for most other
      things (--options, refs, paths, etc.).  'git -c', however, expects
      them in a single option joined by a '=' character, i.e.
      'section.name=value', so we should append a '=' character to each
      fully completed variable name, but no space, so the user can continue
      typing the value right away.
      
      Add an option to the __git_complete_config_variable_name() function to
      allow callers to specify an alternate suffix to add, and use it to
      append that '=' character to configuration variables.  Update the
      __gitcomp() helper function to not append a trailing space to any
      completion words ending with a '=', not just to those option with a
      stuck argument.
      Signed-off-by: NSZEDER Gábor <szeder.dev@gmail.com>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      e1e00089
    • S
      completion: deduplicate configuration sections · d9438873
      SZEDER Gábor 提交于
      The number of configuration variables listed by the completion script
      grew quite when we started to auto-generate it from the documentation
      [1], so we now complete them in two steps: first we list only the
      section names, then the rest [2].  To get the section names we simply
      strip everything following the first dot in each variable name,
      resulting in a lot of repeated section names, because most sections
      contain more than one configuration variable.  This is not a
      correctness issue in practice, because Bash's completion facilities
      remove all repetitions anyway, but these repetitions make testing a
      bit harder.
      
      Replace the small 'sed' script removing subsections and variable names
      with an 'awk' script that does the same, and in addition removes any
      repeated configuration sections as well (by first creating and filling
      an associative array indexed by all encountered configuration
      sections, and then iterating over this array and printing the indices,
      i.e. the unique section names).  This change makes the failing 'git
      config - section' test in 't9902-completion.sh' pass.
      
      Note that this changes the order of section names in the output, and
      makes it downright undeterministic, but this is not an issue, because
      Bash sorts them before presenting them to the user, and our completion
      tests sort them as well before comparing with the expected output.
      
      Yeah, it would be simpler and shorter to just append '| sort -u' to
      that command, but that would incur the overhead of one more external
      process and pipeline stage every time a user completes configuration
      sections.
      
      [1] e17ca926 (completion: drop the hard coded list of config vars,
          2018-05-26)
      [2] f22f6826 (completion: complete general config vars in two steps,
          2018-05-27)
      Signed-off-by: NSZEDER Gábor <szeder.dev@gmail.com>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      d9438873
    • S
      completion: add tests for 'git config' completion · 7a09a8f0
      SZEDER Gábor 提交于
      The next patches will change/refactor the way we complete
      configuration variable names and values, so add a few tests to cover
      the basics, namely the completion of matching configuration sections,
      full variable names, and their values.
      
      Note that the test checking the completion of configuration sections
      is currently failing, though it's not a sign of an actual bug.  If a
      section contains multiple variables, then that section is currently
      repeated as many times as the number of variables in there.  This is
      not a correctness issue in practice, because Bash's completion
      facilities remove all repetitions anyway.  Consequently, we could list
      all those repeated sections in the expected output of this test as
      well, but then it would have to be updated whenever a new
      configuration variable is added to those sections.  Instead, list each
      matching configuration section only once, mark the test as failing for
      now, and the next patch will update the completion script to avoid
      those repetitions.
      Signed-off-by: NSZEDER Gábor <szeder.dev@gmail.com>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      7a09a8f0
  12. 22 6月, 2019 1 次提交
    • Æ
      tests: make GIT_TEST_GETTEXT_POISON a boolean · 1ff750b1
      Ævar Arnfjörð Bjarmason 提交于
      Change the GIT_TEST_GETTEXT_POISON variable from being "non-empty?" to
      being a more standard boolean variable.
      
      Since it needed to be checked in both C code and shellscript (via test
      -n) it was one of the remaining shellscript-like variables. Now that
      we have "env--helper" we can change that.
      
      There's a couple of tricky edge cases that arise because we're using
      git_env_bool() early, and the config-reading "env--helper".
      
      If GIT_TEST_GETTEXT_POISON is set to an invalid value die_bad_number()
      will die, but to do so it would usually call gettext(). Let's detect
      the special case of GIT_TEST_GETTEXT_POISON and always emit that
      message in the C locale, lest we infinitely loop.
      
      As seen in the updated tests in t0017-env-helper.sh there's also a
      caveat related to "env--helper" needing to read the config for trace2
      purposes.
      
      Since the C_LOCALE_OUTPUT prerequisite is lazy and relies on
      "env--helper" we could get invalid results if we failed to read the
      config (e.g. because we'd loop on includes) when combined with
      e.g. "test_i18ngrep" wanting to check with "env--helper" if
      GIT_TEST_GETTEXT_POISON was true or not.
      
      I'm crossing my fingers and hoping that a test similar to the one I
      removed in the earlier "config tests: simplify include cycle test"
      change in this series won't happen again, and testing for this
      explicitly in "env--helper"'s own tests.
      
      This change breaks existing uses of
      e.g. GIT_TEST_GETTEXT_POISON=YesPlease, which we've documented in
      po/README and other places. As noted in [1] we might want to consider
      also accepting "YesPlease" in "env--helper" as a special-case.
      
      But as the lack of uproar over 6cdccfce ("i18n: make GETTEXT_POISON
      a runtime option", 2018-11-08) demonstrates the audience for this
      option is a really narrow set of git developers, who shouldn't have
      much trouble modifying their test scripts, so I think it's better to
      deal with that minor headache now and make all the relevant GIT_TEST_*
      variables boolean in the same way than carry the "YesPlease"
      special-case forward.
      
      1. https://public-inbox.org/git/xmqqtvckm3h8.fsf@gitster-ct.c.googlers.com/Signed-off-by: NÆvar Arnfjörð Bjarmason <avarab@gmail.com>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      1ff750b1
  13. 21 3月, 2019 2 次提交
  14. 09 1月, 2019 1 次提交
    • T
      checkout: introduce --{,no-}overlay option · 091e04bc
      Thomas Gummerer 提交于
      Currently 'git checkout' is defined as an overlay operation, which
      means that if in 'git checkout <tree-ish> -- [<pathspec>]' we have an
      entry in the index that matches <pathspec>, but that doesn't exist in
      <tree-ish>, that entry will not be removed from the index or the
      working tree.
      
      Introduce a new --{,no-}overlay option, which allows using 'git
      checkout' in non-overlay mode, thus removing files from the working
      tree if they do not exist in <tree-ish> but match <pathspec>.
      
      Note that 'git checkout -p <tree-ish> -- [<pathspec>]' already works
      this way, so no changes are needed for the patch mode.  We disallow
      'git checkout --overlay -p' to avoid confusing users who would expect
      to be able to force overlay mode in 'git checkout -p' this way.
      
      Untracked files are not affected by this change, so 'git checkout
      --no-overlay HEAD -- untracked' will not remove untracked from the
      working tree.  This is so e.g. 'git checkout --no-overlay HEAD -- dir/'
      doesn't delete all untracked files in dir/, but rather just resets the
      state of files that are known to git.
      Suggested-by: NJunio C Hamano <gitster@pobox.com>
      Signed-off-by: NThomas Gummerer <t.gummerer@gmail.com>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      091e04bc
  15. 04 1月, 2019 1 次提交
    • C
      completion: treat results of git ls-tree as file paths · 6d54f528
      Chayoung You 提交于
      Let's say there are files named 'foo bar.txt', and 'abc def/test.txt' in
      repository. When following commands trigger a completion:
      
          git show HEAD:fo<Tab>
          git show HEAD:ab<Tab>
      
      The completion results in bash/zsh:
      
          git show HEAD:foo bar.txt
          git show HEAD:abc def/
      
      Where the both of them have an unescaped space in paths, so they'll be
      misread by git. All entries of git ls-tree either a filename or a
      directory, so __gitcomp_file() is proper rather than __gitcomp_nl().
      
      Note the commit f12785a3, which handles quoted paths properly. Like this
      case, we should dequote $cur_ for ?*:* case. For example, let's say
      there is untracked directory 'abc deg', then trigger a completion:
      
          git show HEAD:abc\ de<Tab>
          git show HEAD:'abc de<Tab>
          git show HEAD:"abc de<Tab>
      
      should uniquely complete 'abc def', but bash completes 'abc def' and
      'abc deg' instead. In zsh, triggering a completion:
      
          git show HEAD:abc\ def/<Tab>
      
      should complete 'test.txt', but nothing comes. The both problems will be
      resolved by dequoting paths.
      
      __git_complete_revlist_file() passes arguments to __gitcomp_nl() where
      the first one is a list something like:
      
          abc def/Z
          foo bar.txt Z
      
      where Z is the mark of the EOL.
      
      - The trailing space of blob in __git ls-tree | sed.
        It makes the completion results become:
      
            git show HEAD:foo\ bar.txt\ <CURSOR>
      
        So git will try to find a file named 'foo bar.txt ' instead.
      
      - The trailing slash of tree in __git ls-tree | sed.
        It makes the completion results on zsh become:
      
            git show HEAD:abc\ def/ <CURSOR>
      
        So that the last space on command like should be removed on zsh to
        complete filenames under 'abc def/'.
      Signed-off-by: NChayoung You <yousbe@gmail.com>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      6d54f528
  16. 14 12月, 2018 1 次提交
  17. 20 11月, 2018 1 次提交
    • S
      tests: send "bug in the test script" errors to the script's stderr · 165293af
      SZEDER Gábor 提交于
      Some of the functions in our test library check that they were invoked
      properly with conditions like this:
      
        test "$#" = 2 ||
        error "bug in the test script: not 2 parameters to test-expect-success"
      
      If this particular condition is triggered, then 'error' will abort the
      whole test script with a bold red error message [1] right away.
      
      However, under certain circumstances the test script will be aborted
      completely silently, namely if:
      
        - a similar condition in a test helper function like
          'test_line_count' is triggered,
        - which is invoked from the test script's "main" shell [2],
        - and the test script is run manually (i.e. './t1234-foo.sh' as
          opposed to 'make t1234-foo.sh' or 'make test') [3]
        - and without the '--verbose' option,
      
      because the error message is printed from within 'test_eval_', where
      standard output is redirected either to /dev/null or to a log file.
      The only indication that something is wrong is that not all tests in
      the script are executed and at the end of the test script's output
      there is no "# passed all N tests" message, which are subtle and can
      easily go unnoticed, as I had to experience myself.
      
      Send these "bug in the test script" error messages directly to the
      test scripts standard error and thus to the terminal, so those bugs
      will be much harder to overlook.  Instead of updating all ~20 such
      'error' calls with a redirection, let's add a BUG() function to
      'test-lib.sh', wrapping an 'error' call with the proper redirection
      and also including the common prefix of those error messages, and
      convert all those call sites [4] to use this new BUG() function
      instead.
      
      [1] That particular error message from 'test_expect_success' is
          printed in color only when running with or without '--verbose';
          with '--tee' or '--verbose-log' the error is printed without
          color, but it is printed to the terminal nonetheless.
      
      [2] If such a condition is triggered in a subshell of a test, then
          'error' won't be able to abort the whole test script, but only the
          subshell, which in turn causes the test to fail in the usual way,
          indicating loudly and clearly that something is wrong.
      
      [3] Well, 'error' aborts the test script the same way when run
          manually or by 'make' or 'prove', but both 'make' and 'prove' pay
          attention to the test script's exit status, and even a silently
          aborted test script would then trigger those tools' usual
          noticable error messages.
      
      [4] Strictly speaking, not all those 'error' calls need that
          redirection to send their output to the terminal, see e.g.
          'test_expect_success' in the opening example, but I think it's
          better to be consistent.
      Signed-off-by: NSZEDER Gábor <szeder.dev@gmail.com>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      165293af
  18. 14 11月, 2018 1 次提交
    • N
      checkout: disambiguate dwim tracking branches and local files · be4908f1
      Nguyễn Thái Ngọc Duy 提交于
      When checkout dwim is added in [1], it is restricted to only dwim when
      certain conditions are met and fall back to default checkout behavior
      otherwise. It turns out falling back could be confusing. One of the
      conditions to turn
      
          git checkout frotz
      
      to
      
          git checkout -b frotz origin/frotz
      
      is that frotz must not exist as a file. But when the user comes to
      expect "git checkout frotz" to create the branch "frotz" and there
      happens to be a file named "frotz", git's silently reverting "frotz"
      file content is not helping. This is reported in Git mailing list [2]
      and even used as an example of "Git is bad" elsewhere [3].
      
      We normally try to do the right thing, but when there are multiple
      "right things" to do, it's best to leave it to the user to decide.
      Check this case, ask the user to to disambiguate:
      
      - "git checkout -- foo" will check out path "foo"
      - "git checkout foo --" will dwim and create branch "foo" [4]
      
      For users who do not want dwim, use --no-guess. It's useless in this
      particular case because "git checkout --no-guess foo --" will just
      fail. But it could be used by scripts.
      
      [1] 70c9ac2f (DWIM "git checkout frotz" to "git checkout -b frotz
          origin/frotz" - 2009-10-18)
      [2] https://public-inbox.org/git/CACsJy8B2TVr1g+k+eSQ=pBEO3WN4_LtgLo9gpur8X7Z9GOFL_A@mail.gmail.com/
      [3] https://news.ycombinator.com/item?id=18230655
      [4] a047fafc (checkout: allow dwim for branch creation for "git
          checkout $branch --" - 2013-10-18)
      Signed-off-by: NNguyễn Thái Ngọc Duy <pclouds@gmail.com>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      be4908f1
  19. 09 11月, 2018 1 次提交
    • Æ
      i18n: make GETTEXT_POISON a runtime option · 6cdccfce
      Ævar Arnfjörð Bjarmason 提交于
      Change the GETTEXT_POISON compile-time + runtime GIT_GETTEXT_POISON
      test parameter to only be a GIT_TEST_GETTEXT_POISON=<non-empty?>
      runtime parameter, to be consistent with other parameters documented
      in "Running tests with special setups" in t/README.
      
      When I added GETTEXT_POISON in bb946bba ("i18n: add GETTEXT_POISON
      to simulate unfriendly translator", 2011-02-22) I was concerned with
      ensuring that the _() function would get constant folded if NO_GETTEXT
      was defined, and likewise that GETTEXT_POISON would be compiled out
      unless it was defined.
      
      But as the benchmark in my [1] shows doing a one-off runtime
      getenv("GIT_TEST_[...]") is trivial, and since GETTEXT_POISON was
      originally added the GIT_TEST_* env variables have become the common
      idiom for turning on special test setups.
      
      So change GETTEXT_POISON to work the same way. Now the
      GETTEXT_POISON=YesPlease compile-time option is gone, and running the
      tests with GIT_TEST_GETTEXT_POISON=[YesPlease|] can be toggled on/off
      without recompiling.
      
      This allows for conditionally amending tests to test with/without
      poison, similar to what 859fdc0c ("commit-graph: define
      GIT_TEST_COMMIT_GRAPH", 2018-08-29) did for GIT_TEST_COMMIT_GRAPH. Do
      some of that, now we e.g. always run the t0205-gettext-poison.sh test.
      
      I did enough there to remove the GETTEXT_POISON prerequisite, but its
      inverse C_LOCALE_OUTPUT is still around, and surely some tests using
      it can be converted to e.g. always set GIT_TEST_GETTEXT_POISON=.
      
      Notes on the implementation:
      
       * We still compile a dedicated GETTEXT_POISON build in Travis
         CI. Perhaps this should be revisited and integrated into the
         "linux-gcc" build, see ae59a4e4 ("travis: run tests with
         GIT_TEST_SPLIT_INDEX", 2018-01-07) for prior art in that area. Then
         again maybe not, see [2].
      
       * We now skip a test in t0000-basic.sh under
         GIT_TEST_GETTEXT_POISON=YesPlease that wasn't skipped before. This
         test relies on C locale output, but due to an edge case in how the
         previous implementation of GETTEXT_POISON worked (reading it from
         GIT-BUILD-OPTIONS) wasn't enabling poison correctly. Now it does,
         and needs to be skipped.
      
       * The getenv() function is not reentrant, so out of paranoia about
         code of the form:
      
             printf(_("%s"), getenv("some-env"));
      
         call use_gettext_poison() in our early setup in git_setup_gettext()
         so we populate the "poison_requested" variable in a codepath that's
         won't suffer from that race condition.
      
       * We error out in the Makefile if you're still saying
         GETTEXT_POISON=YesPlease to prompt users to change their
         invocation.
      
       * We should not print out poisoned messages during the test
         initialization itself to keep it more readable, so the test library
         hides the variable if set in $GIT_TEST_GETTEXT_POISON_ORIG during
         setup. See [3].
      
      See also [4] for more on the motivation behind this patch, and the
      history of the GETTEXT_POISON facility.
      
      1. https://public-inbox.org/git/871s8gd32p.fsf@evledraar.gmail.com/
      2. https://public-inbox.org/git/20181102163725.GY30222@szeder.dev/
      3. https://public-inbox.org/git/20181022202241.18629-2-szeder.dev@gmail.com/
      4. https://public-inbox.org/git/878t2pd6yu.fsf@evledraar.gmail.com/Signed-off-by: NÆvar Arnfjörð Bjarmason <avarab@gmail.com>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      6cdccfce
  20. 07 8月, 2018 1 次提交
    • W
      t: factor out FUNNYNAMES as shared lazy prereq · 6ec63305
      William Chargin 提交于
      A fair number of tests need to check that the filesystem supports file
      names including "funny" characters, like newline, tab, and double-quote.
      Jonathan Nieder suggested that this be extracted into a lazy prereq in
      the top-level `test-lib.sh`. This patch effects that change.
      
      The FUNNYNAMES prereq now uniformly requires support for newlines, tabs,
      and double-quotes in filenames. This very slightly decreases the power
      of some tests, which might have run previously on a system that supports
      (e.g.) newlines and tabs but not double-quotes, but now will not. This
      seems to me like an acceptable tradeoff for consistency.
      
      One test (`t/t9902-completion.sh`) defined FUNNYNAMES to further require
      the separators \034 through \037, the test for which was implemented
      using the Bash-specific $'\034' syntax. I've elected to leave this one
      as is, renaming it to FUNNIERNAMES.
      
      After this patch, `git grep 'test_\(set\|lazy\)_prereq.*FUNNYNAMES'` has
      only one result.
      Signed-off-by: NWilliam Chargin <wchargin@gmail.com>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      6ec63305
  21. 17 7月, 2018 1 次提交