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
Michael J Gruber <git@drmicha.warpmail.net>
Date
Sep 7, 2016, 08:52 UTC
Message-ID
<24dcd36d-dce9-879b-5bb0-0c40021be47f@drmicha.warpmail.net>
In-Reply-To
<CAKmQUfbemaid61xPyvNheLM2jVGXGjiyF_x=NZnxkZ=5wccQ=Q@mail.gmail.com>
john smith venit, vidit, dixit 06.09.2016 23:01:
Show 66 quoted lines
> On 9/6/16, Torsten Bögershausen <tboegi@web.de> wrote:
>> On 06.09.16 19:47, john smith wrote:
>>> I am looking for a way to force smudge filter to run by simulating a
>>> real life checkout. Let's say I just created a new branch and did not
>>> modify any files but want to test my new smudge filter. According to
>>> some answers such as
>>> https://stackoverflow.com/questions/22909620/git-smudge-clean-filter-between-branches
>>> and
>>> https://stackoverflow.com/questions/21652242/git-re-checkout-files-after-creating-smudge-filter
>>> it should be possible by running:
>>>
>>> git checkout HEAD --
>>>
>>> but in doesn't work with git 2.9.0. Method suggested in accepted
>>> answer here
>>> https://stackoverflow.com/questions/17223527/how-do-i-force-git-to-checkout-the-master-branch-and-remove-carriage-returns-aft
>>> works but I don't like because it seems fragile. Is there a safe way
>>> to do what I want to do in Git still today?
>>>
>> It depends what you mean with "safe way".
> 
> I want to store all my dotfiles in a single repoitory.  The problem is
> that that some specific pieces of these files are different on
> different machines.  I have a special .conf file that is different on
> every branch and contains machine-specific definitions of some
> variables such as EMAIL or SMTP server.  In my smudge filter I call a
> script which parses .conf file and replace all template variable
> definitions saved in the given file with correct definitions.  For
> example in my ~/.bashrc I have this on all branches:
> 
> export EMAIL="@EMAIL@"
> 
> and in my .conf file on `home' branch
> 
> EMAIL=home@address.com
> 
> and on `work' branch:
> 
> EMAIL=work@address.com
> 
> And in .gitattributes on both branches:
> 
> bash/.bashrc     filter=make-usable
> 
> I also have single `master' branch that only contains template
> dotfiles and no .conf.  When setting up a new machine I could just
> create a new branch off master branch and add a new .conf.
> 
> In turn, clean filter replace all correct definitions in the given
> dotfiles back into template definitions.
> 
> I'd prefer smudge/clean filters instead of `make' scripts etc. to
> convert template dotfiles into something usable and back because
> filters:
> 
> 1. could be run automatically
> 
> 2. do not modify files as shown by `git show HEAD:<file>' and
> therefore no files are reported as modified by git status and also
> there are not conflicts when merging master into work/home branch.
> 
> I have problems because with point 1 because apparently smudge filter
> is not run automatically every time when branch is changed if files
> listed in .gitattributes do not change. As the last resort I could
> force smudge/clean filter to run just to keep advantage specified in
> point 2.

I'm afraid smudge/clean are not a good match for your use case: smudge can do anything that clean removes again, i.e.: if you smudge a blob, then clean it, it has to be the same blob.

Your smudge filter seems to give different results for the same blob depending on other variables (your .conf), but git doesn't care as long as clean output is the same. Also, git cannot possibly know when "it is time" to rerun smudge.

Maybe "source"-ing .conf files would be an alternative approach for you, or using hooks?

Cheers Michael

Previous: john smithNext: Jakub Narębski
Message 4 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.