1

I'm looking over stack overflow and cant find any solution (just lots of not very useful workarounds) to what I can only presume is a very common problem.

I want to ignore some files (token files etc.) changes but keep the general layout in the repository so that I do not have to manually generate the files, just refresh the token etc. I'm aware I can do any of the following.

  1. run: git update-index --assume-unchanged path/to/file but everyone that uses the repository must run this each time they switch branch and run the code so this is not a practical solution.

  2. Make the generation of the files a pre build step from within the CI/CD pipeline But this does not solve the issue for people running the code locally. as outlined here

  3. Write a shell script to generate the files locally in a temp location for anyone that clones the repo for the first time, but this causes difficult to maintain overhead when assets, tokens, profiles etc. constantly being added and removed from the project

Essentially what I am looking for is something that is similar to the --assume-unchanged command in git that will be globally persistent for every user that cloned the repository without extra overhead for them. Maybe this doesn't exist but I thought Id ask because this seems like an incredibly useful feature. and even knowing its not possible would prevent people from having to dig around as much as I have.

Also if this is not possible, does anyone know why? Thanks in advance.

Jack Burke
  • 101
  • 1
  • 6
  • Visual Studio Prebuild Step perhaps? –  Oct 07 '20 at 11:46
  • 1
    Do you mean kind of a "checkout-only" file? We have one of those, too. A file that needs to be there and a Designer Tools makes changes to it. We want to ignore these changes, because they are irrelevant and break other stuff. All works if the file just exists empty. No solution so far, each teammember just hits "undo changes" for the file if it pops up. – Fildor Oct 07 '20 at 12:01
  • @HimBromBeere this is the language I am writing my project in and I thought it may be relevant for solutions for me but not majorly important and so I have removed it – Jack Burke Oct 07 '20 at 15:14
  • 1
    @Fildor yes this is exactly the kind of situation I am considering – Jack Burke Oct 07 '20 at 15:15

1 Answers1

1

What language/packages/environment are you using that requires these tokens? Using git to solve this problem is probably not the right solution. Normally, you would have a configuration file in your repository that referenced another file that is ignored. This other file would only contain the credentials for the local user. All other settings would be in the tracked file.

For example, if you are using a c# webserver, you could use the following solution for your app.config files.

Use XML includes or config references in app.config to include other config files' settings

Edit:

For C# Unit tests, I usually add a line at the start of each test to get the login credentials or use the [TestInitialize] functionality as shown here. This method/function will populate whatever my underlying software needs to run - from a credential standpoint.

    [TestMethod]
    public async Task RunAPITest()
    {
        Common.UnitTestLogin.LoginDev();
        //... Actual Test

If you load your credentials from a json file during actual runtime, you can load that json file in that Initialize step and then from there override/replace the credentials either reading from another json file locally (that is gitignored) or pulling then from an environment variable. This way, your git repository stays clean, but your end users have an easy way to run tests locally.

Ben W
  • 930
  • 6
  • 16
  • specifically in this situation I am storing a Gmail API access token credentials but in the past I have had the same issue with storing chrome profiles and other assets files like JSONs that get modified. For more context I am developing a Test Automation Framework using various API and UI tests in C# and want to allow people to run tests locally with ease. – Jack Burke Oct 07 '20 at 15:21