代码之家  ›  专栏  ›  技术社区  ›  stason

使git显示其运行内容筛选器的特定文件名

  •  1
  • stason  · 技术社区  · 6 年前

    我正在调试配置的git内容过滤器的工作( nbstripout )我正试着 GIT_TRACE

    $ GIT_TRACE=1 git pull origin master
    [...] removed irrelevant sections of the output
    16:49:28.846707 run-command.c:640       trace: run_command: git merge FETCH_HEAD
    16:49:28.849309 git.c:344               trace: built-in: git merge FETCH_HEAD
    Updating 1ea49ad..ae0ba93
    16:49:28.863291 run-command.c:640       trace: run_command: nbstripout
    16:49:28.864700 run-command.c:640       trace: run_command: nbstripout
    16:49:28.866060 run-command.c:640       trace: run_command: nbstripout
    [...] many more of the same
    

    我怎么能得到 GIT_跟踪 run_command 显示传递给筛选器的参数?我在git的手册中查看了其他各种调试环境变量,但是我没有看到任何能够启用该级别调试的东西。

    我知道 git check-attr ,但我想查看运行时跟踪,它在哪些文件上运行筛选器,使用哪些参数。

    1 回复  |  直到 6 年前
        1
  •  2
  •   stason    6 年前

    provided a workaround as an answer . 在杰夫的允许下,我在这里分享他的答案:


    GIT_TRACE应该始终显示参数。但除非你具体说明 clean/smudge filter配置中的参数,则Git不会传递任何参数。 stdin/stdout流是最重要的。

      $ echo '* filter=foo' >.gitattributes
      $ git config filter.foo.clean 'myfilter'
      $ GIT_TRACE=1 git add .
      19:42:16.516401 [pid=14112] git.c:415             trace: built-in: git add .
      19:42:16.517454 [pid=14112] run-command.c:637     trace: run_command: myfilter
    
      $ git config filter.foo.clean 'myfilter --foo'
      $ touch .gitattributes ;# make sure we actually read it again ;)
      $ GIT_TRACE=1 git add .
      19:42:58.122942 [pid=14156] git.c:415             trace: built-in: git add .
      19:42:58.124023 [pid=14156] run-command.c:637     trace: run_command: 'myfilter \
    --foo'
    

    您可以使用%f传递文件名,例如:

      $ git config filter.foo.clean 'myfilter %f'
      $ touch .gitattributes
      $ GIT_TRACE=1 git add .
      19:44:51.187177 [pid=14318] git.c:415             trace: built-in: git add .
      19:44:51.188256 [pid=14318] run-command.c:637     trace: run_command: 'myfilter \
    '\''.gitattributes'\'''
    

    争论。对于一个“干净”的过滤器,可能是可以的(例如,如果它只是告诉 从文件系统而不是stdin读取的过滤器),但是 几乎肯定不是你想要的“污迹”过滤器。

      git config filter.foo.clean 'f() { echo >&2 "cleaning $1"; myfilter ...; }; f %f'
    

      $ git add .
      cleaning .gitattributes
    

    或者,如果您真的只想触发GIT_TRACE,请尝试以下操作:

      $ git config filter.foo.clean 'f() { myfilter; }; f %f'
      19:52:52.874064 [pid=14719] git.c:415             trace: built-in: git add .
      19:52:52.875115 [pid=14719] run-command.c:637     trace: run_command: 'f() { \
    myfilter; }; f '\''.gitattributes'\'''
    

    在跟踪输出中可以得到名称,但是调用的命令


    所以我最后用了:

    [filter "nbstripout"]
        clean  = "f() { echo >&2 \"clean: nbstripout $1\"; nbstripout; }; f %f"
        smudge = "f() { echo >&2 \"smudge: cat $1\"; cat; }; f %f"
        required = true
    

    现在我在运行时记录文件名 GIT_TRACE=1 ,没有它。


    在一个 followup