5

I have a feature branch and a testing branch (for initial regression). I would like to have a working copy available for my testing branch for the testing environment. However, I need to compress some of the source code (not into binary, just optimize) via a script. I can enact this script via a post-receive Git hook.

I'm trying to design my bash script (for CI) so that it's fairly robust and want to avoid automation causing Git conflicts. I'm thinking of having a main repository (origin) and a testing environment repository (ci_test) simply to allow CI to commit.

I'm thinking about pushing to ci_test/testing when promoting source. CI should compress, add, commit, fetch from origin/testing, merge if necessary (taking theirs-full iff conflicts), then push to origin/testing.

The problem to my model above is that Git complains when I attempt to push to ci_test/testing because it has a working copy (makes sense, because they may not be synced). Is there a proper (automated) way to use Continuous Integration scripts with Git so that they're still tracked?

BLaZuRE
  • 2,356
  • 2
  • 26
  • 43

1 Answers1

2

The problem to my model above is that Git complains when I attempt to push to ci_test/testing because it has a working copy (makes sense, because they may not be synced).

You can either:

  • make sure your ci_test is a bare repo, with a post-receive hook which would:

  • or, if you are the only one pushing to that ci_testing remote repo, configure the remote Git to accept pushes to a non-bare repo.
    This is possible since Git 2.3+ with:

    git config receive.denyCurrentBranch updateInstead
    

And with Git 2.4+, you can setup the remote ci_testing with a "push-to-checkout" hook, which can be installed on the server to customize exactly what happens when a user pushes to the checked-out branch.

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • [Push-to-checkout](https://git-scm.com/docs/githooks#_push_to_checkout) hook looks promising. I wasn't aware of that hook existing. The reason I wanted ci_test to have a working copy is because the hook would modify source and I want to commit changes (I can't imagine being able to do that without a working copy). I'm also using the working copy as the directory that is used to read the testing version of the application. – BLaZuRE Jan 14 '17 at 20:35
  • @BLaZuRE yes, in your case, push-to-checkout seems a good fit. – VonC Jan 14 '17 at 20:36