0

I have branch_a (development branch) in repo_A and branch_b in repo_B (production branch). Both repos are on Cloud Source. Their history is the same, except for the last commit(s) in branch_a.

How to make CloudBuild push last commit(s) from repo_A/branch_a to repo_B/branch_b?

CloudBuild gets triggered with a push to repo_A/branch_a. CloudBuild fetches repo_A/branch_a into the working directory

I managed to add repo_B/branch_b as remote. But when I try to push 'master' to repo_B/branch_b I get:

src refspec branch_b does not match any
failed to push some refs to repo_B

git remote -v lists both remotes: repo_A and repo_B

CloudBuild service account has access to both repos

syldman
  • 505
  • 1
  • 6
  • 18
  • I found a very [similar case](https://stackoverflow.com/questions/70018022) that could help you. The error log is similar to [this one](https://stackoverflow.com/questions/4181861) for troubleshooting. You can also give this guides a read: [Triggers](https://cloud.google.com/build/docs/automating-builds/create-manage-triggers) and [Automatic Builds](https://cloud.google.com/source-repositories/docs/integrating-with-cloud-build). Could you please share your `cloudbuild.yaml` file or at least what you have tried so far to provide better support? – Alex Feb 04 '22 at 23:36
  • `src refspec branch_b does not match any` says that you did not try to push `master` but rather `branch_b`. It's important to get your refspecs rightl; read up on Git push refspecs. – torek Feb 05 '22 at 07:26
  • @Alex, I'm not using Github. Checked those links. GCP guides don't cover this case. – syldman Feb 05 '22 at 18:27
  • @torek, I checked current branch and it's 'master', not 'branch_b'. – syldman Feb 05 '22 at 19:49
  • OK - so why did you run `git push repo_B branch_b`, and not `git push repo_B master`? – torek Feb 06 '22 at 00:05
  • @torek sorry, made a mistake when posting the question – syldman Feb 08 '22 at 19:52

1 Answers1

3

For the future generations

The problem was that Cloud Build was pulling only the last commit from repo_A, thus comparing to repo_B/branch_B was showing inconsistent history.

git pull --unshallow did the trick.

syldman
  • 505
  • 1
  • 6
  • 18