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
Jakub Narębski <jnareb@gmail.com>
Date
Sep 10, 2016, 10:32 UTC
Message-ID
<a00fa147-291c-536c-35da-56f88221e0f8@gmail.com>
In-Reply-To
<CAKmQUfYCUq=kUTau1-3NjjPVBk6WkP3KdTjgMC8sZtU8h=H4iQ@mail.gmail.com>
W dniu 10.09.2016 o 01:07, john smith pisze:
Show 10 quoted lines
> On 9/10/16, Junio C Hamano <gitster@pobox.com> wrote:
>> The clean and smudge operations should look _only_ at the contents
>> they are filtering, and nothing else, and the clean/smudge filtering
>> mechanism is designed to support that use case.  It is not designed
>> to do things like embedding the name of the branch that is being
>> checked out into the result.
> 
> Ok, I think I get it. It was actually my original problem with smudge
> filters because I wanted them to be run after *every* checkout even if
> file contents stayed the same (hence the subject).
And that's not the case, for performance reasons.
Show 9 quoted lines
> 
> Now Jakub suggested post-checkout hook in conjunction with only clean
> filter for my problem of managing dotfiles but I think I don't fully
> get it.  The problem is that in the scenario presented in my last
> e-mail clean filter is run in the situation which doesn't like a
> checkin to me.  Is `git checkout <PATH>' doing a *checkin*" under the
> hood so that the clean filter is called?  What does actually `checkin'
> mean in Git?  I thought that checkin it's the same as committing a
> file into the repository.
I was wrong, I'm sorry. My mistake.

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).

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'
Or something like that.
-- 
Jakub Narębski
Previous: Junio C HamanoNext: john smith
Message 10 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.