3

I'm trying to use Git's smudge/clean filters to create a file that can differ based on environment.

In my repo, I have the following files:

/root/scripts/data.config.local
/root/scripts/data.config.staging
/root/scripts/data.config.production

When a checkout occurs on the developer machine, I want the data.config.local file to be copied to the /root/scripts directory as "data.config".

My global .gitconfig has the following filter definition:

[filter "copyEnv"]
  clean = "rm -f c:\\code4x\\git\\rgpstage\\scripts\\gg_data.config"
  smudge = "cp c:\\code4x\\git\\rgpstage\\scripts\\gg_data.config.local c:\\code4x\\git\\rgpstage\\scripts\\gg_data.config"

I've tried a number of variations on these filters, including moving the scripts to separate script files. My separate script file for smudge looks like this:

#! /usr/bin/bash
cp "C:\Code4X\GIT\rgpstage\scripts\gg_data.config.local" "C:\Code4X\GIT\rgpstage\scripts\gg_data.config"

I get the following output regardless of which approach I use for my filter action (either inline or file):

error: cannot feed the input to external filter c:\removeGGData
error: external filter c:\removeGGData failed
cp: cannot stat `C:\\Code4X\\GIT\\rgpstage\\scripts\\gg_data.config.local': No such file or directory
error: cannot feed the input to external filter c:\copyGGData
error: external filter c:\copyGGData failed 1
error: external filter c:\copyGGData failed

I'm running this on Windows 7, using Git 1.8. The file does exist and is opened in terms of permissions.

Andrew Barber
  • 39,603
  • 20
  • 94
  • 123
David Hoerster
  • 28,421
  • 8
  • 67
  • 102

1 Answers1

1

You seem to have a misunderstanding about smudge and clean filters (btw – what does your .gitattributes look like?). What you are doing is a serious abuse of that feature. These filters are meant to filter a file, passed to them on STDIN with a filtered version given back on STDOUT. These fitlers should definitely never have any side effects.

So to achieve different configurations on different machines, I would recommend putting them all into the same file and surrounding them with an if-statement, that uses information from a smudge filter. For details see my answer here: https://stackoverflow.com/a/13616911/758345

Community
  • 1
  • 1
Chronial
  • 66,706
  • 14
  • 93
  • 99