Replace several information during git commit using filter

37 Views Asked by At

In my source code (".ino" file), I have saved my Wifi credentials. Using git commit, my personal Wifi information should be replaced by general information. Therefore I'm using the "clean/smudge filter" which is explained here and here.

In my working directory, there are the following lines in my source code:

/* Wifi definitions */
const char* WIFI_SSID = "My personal Wifi"; // Wifi ssid
const char* WIFI_PSK = "Password1234";      // Wifi psk

After using git commit, it should look like this:

/* Wifi definitions */
const char* WIFI_SSID = "WIFI_SSID";    // Wifi ssid
const char* WIFI_PSK = "WIFI_PSK";      // Wifi psk

Therefore I added in the .git/info folder the file "attributes" with the following content: *.ino filter=WifiFilter.

Additionally, I defined the filters as follows:

git config --global filter.WifiFilter.clean 'sed -e "s/My personal Wifi/WIFI_SSID/g" -e "s/Password1234/WIFI_PSK/g"'
git config --global filter.WifiFilter.smudge 'sed -e "s/WIFI_SSID/My personal Wifi/g" -e "s/WIFI_PSK/Password1234/g"'

Unfortunately, only one filter works. After the commit, it looks like this:

/* Wifi definitions */
const char* WIFI_SSID = "WIFI_SSID";        // Wifi ssid
const char* WIFI_PSK = "Password1234";      // Wifi psk

Does anyone have an idea what it could be?

1

There are 1 best solutions below

0
On BEST ANSWER

Solved. It works with the aboved mentioned configuration. My mistake was: I had a local 'git config' configuration with a filter rule which only replaces the "WIFI_SSID". After deleting the local 'git config' filter configuration, it works with the global 'git config' configuration.