git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: How to simulate a real checkout to test a new smudge filter?

From
JSjohn smith <wempwer@gmail.com>
Date
Sep 10, 2016, 16:31 UTC
Message-ID
<CAKmQUfagUP6xia5_KjQ=pdtBzU2DHpV0=F1FGCh0P1yWNY5Hfw@mail.gmail.com>
In-Reply-To
<a00fa147-291c-536c-35da-56f88221e0f8@gmail.com>
On 9/10/16, Jakub Narębski <jnareb@gmail.com> wrote:
Show 6 quoted lines
> You would need post-checkout hook together with clean / smudge filters
> (though you could get by without smudge filter, at least in theory...).
> The `post-checkout` hook could run e.g. "git checkout -- '*.conf'"
> to force use of smudge filter, after checking that it was a change
> of branch ("git checkout <commit-ish>").  See githooks(5) for details
> (last, third parameter passed to hook script is 1, rather than 0).

Neat idea. I could still have an advantage of filter as git status wouldn't show that files are changed and there would be no merge conflicts and additionally filters would run after every checkout even if files stayed the same. But are sure that `git checkout -- <FILE>' actually forces checkout and runs smudge filter? It doesn't work for me neither with 2.9.0 nor 2.10.0.85.gcda1bbd. For a minimal example, let's say that I have this in .gitattributes:

a     filter=test-filter
And this in .git/config:
smudge = touch /tmp/SMUDGE_RUN && cat

And also have a tracked file named `a' in the repository. Now this should create /tmp/SMUDGE_RUN:

git checkout  -- a
but it doesn't.
This also doesn't work:
git checkout -f -- a
But this does:
git checkout HEAD^ && git co -
Show 16 quoted lines
> Unfortunately I don't see a way to query .gitattributes files to
> find out all patterns that match specific attribute; you would need
> to duplicate configuration:
>
>   .gitattributes:
>   *.conf filter=transform
>
>   .git/config
>   [filter "transform"]
>   	clean  = replace-with-placeholder %f
>   	smudge = expand-with-branchname %f
>
>   .git/hooks/post-checkout
>   #!/bin/sh
>
>   test "$3" -eq "1" && git checkout -- '*.conf'

It's a secondary issue, but - in my repository I only have one .conf file on every branch with real definitions of machine-specific variables and a number of various config files for various programs such as bash/.bashrc or screen/.screenrc so in my case it would be:

  .gitattributes:
  bash/.basrc filter=transform
  git/.gitconfig filter=transform
  (...)
  .git/config
  [filter "transform"]
        clean  = replace-with-placeholder %f
        smudge = expand-with-branchname %f
  .git/hooks/post-checkout
  #!/bin/sh
  test "$3" -eq "1" && (
       git checkout -- bash/.bashrc &&
       git checkout -- git/.gitconfig
       (...)
       )

Of course a list of files in .git/hooks/post-checkout could be generated at runtime from first column of .gitattributes.

-- 
<wempwer@gmail.com>
Previous: Jakub Narębski
Message 11 of 11 in “How to simulate a real checkout to test a new smudge filter?”
  1. john smithSep 6, 2016
  2. Torsten BögershausenSep 6, 2016
  3. john smithSep 6, 2016
  4. Michael J GruberSep 7, 2016
  5. Jakub NarębskiSep 8, 2016
  6. john smithSep 9, 2016
  7. Junio C HamanoSep 9, 2016
  8. john smithSep 9, 2016
  9. Junio C HamanoSep 9, 2016
  10. Jakub NarębskiSep 10, 2016
  11. john smithSep 10, 2016

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.