Question

We have some devs pushing to a remote bare repo on a server, and would like to do something like automate a push to perforce nightly using git p4 from this central bare repo. But am running into a snag because it seems you can't run git p4 submit outside of a working tree.

What's the recommended way to deal with something like this?

Était-ce utile?

La solution

I do something similar with a script that runs every few minutes and does a 2-way sync between git and p4. But git-p4 can't work without both a checked-out git tree and a p4 repo. In all you end up with 3 versions of your source:

  1. the bare git repo
  2. checked-out git repo for 'git p4' to do its work in
  3. p4 checkout to submit to p4 from.

Developers push to a bare git repo (held on gitolite), using a branch called 'dev'. Then every few minutes, there's a script that does:

  1. update the checked-out git tree (git pull --rebase)
  2. pull down latest upstream p4 changes into p4/master (git p4 sync)
  3. rebase git world against p4 world (git rebase p4/master)
  4. send git changes to p4 (git p4 submit)
  5. rewrite the 'dev' branch (git push origin +HEAD:dev)

Gotchas

  1. Merge conflicts. These actually occur very infrequently but can cause a few problems.

  2. I had to add some locking around the whole thing so that developers don't lose changes if they push a change between (1) and (5). The locking just creates a lock directory that then gets used in one of the hook scripts to delay pushes.

  3. RCS keywords. Newer versions of 'git p4' now copes with RCS keywords but originally it didn't, so the whole thing would occasionally get stuck as they cause merge conflicts.

It took a while to setup but it's now been going for 18 months with 100+ developers with very few incidents.

Autres conseils

It might be easiest not to use git-p4, but merely have a checkout of the git tree which is also a perforce checkout, and script everything from there? i.e. do a git pull, parse the output to edit appropriate files, add new ones, delete removed ones, then commit into perforce?

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top