@@ -408,17 +408,29 @@ type PushSpec struct {
408408 // Branch specifies that commits should be pushed to the branch
409409 // named. The branch is created using ` .spec.checkout.branch` as the
410410 // starting point, if it doesn't already exist.
411- // +required
412- Branch string `json:"branch"`
411+ // +optional
412+ Branch string `json:"branch,omitempty"`
413+
414+ // Refspec specifies the Git Refspec to use for a push operation.
415+ // If both Branch and Refspec are provided, then the commit is pushed
416+ // to the branch and also using the specified refspec.
417+ // For more details about Git Refspecs, see:
418+ // https://git-scm.com/book/en/v2/Git-Internals-The-Refspec
419+ // +optional
420+ Refspec string `json:"refspec,omitempty"`
413421}
414422```
415423
416- If ` push ` is not present, commits are made on the branch given in ` .spec.git.checkout.branch ` and
424+ If ` . push` is not present, commits are made on the branch given in ` .spec.git.checkout.branch ` and
417425pushed to the same branch at the origin. If ` .spec.git.checkout ` is not present, it will fall back
418426to the branch given in the ` GitRepository ` referenced by ` .spec.sourceRef ` . If none of these yield a
419427branch name, the automation will fail.
420428
421- When ` push ` is present, the ` branch ` field specifies a branch to push to at the origin. The branch
429+ If ` .push.refspec ` is present, the refspec specified is used to perform the push operation.
430+ An example of a valid refspec is ` refs/heads/branch:refs/heads/branch ` . This allows users to
431+ push to an arbitary destination reference.
432+
433+ If ` .push.branch ` is present, the specified branch is pushed to at the origin. The branch
422434will be created locally if it does not already exist, starting from the checkout branch. If it does
423435already exist, it will be overwritten with the cloned version plus the changes made by the
424436controller. Alternatively, force push can be disabled by starting the controller with ` --feature-gates=GitForcePushBranch=false ` ,
@@ -427,6 +439,16 @@ Note that without force push in push branches, if the target branch is stale, th
427439be able to conclude the operation and will consistently fail until the branch is either deleted or
428440refreshed.
429441
442+ If both ` .push.refspec ` and ` .push.branch ` are specified, then the reconciler will perform
443+ two push operations, one to the specified branch and another using the specified refspec.
444+ This is particularly useful for working with Gerrit servers. For more information about this,
445+ please refer to the [ Gerrit] ( #Gerrit ) section.
446+
447+ ** Note:** If both ` .push.refspec ` and ` .push.branch ` are essentially equal to
448+ each other (for e.g.: ` .push.refspec: refs/heads/main:refs/heads/main ` and
449+ ` .push.branch: main ` ), then the reconciler might fail to perform the second push
450+ operation and error out with an ` already up-to-date ` error.
451+
430452In the following snippet, updates will be pushed as commits to the branch ` auto ` , and when that
431453branch does not exist at the origin, it will be created locally starting from the branch ` main ` , and
432454pushed:
@@ -441,6 +463,21 @@ spec:
441463 branch : auto
442464` ` `
443465
466+ In the following snippet, updates and commits will be made on the ` auto` branch locally.
467+ The commits will be then pushed to the `auto` branch and then using the `refs/heads/auto:refs/heads/main`
468+ refspec :
469+
470+ ` ` ` yaml
471+ spec:
472+ git:
473+ checkout:
474+ ref:
475+ branch: main
476+ push:
477+ branch: auto
478+ refspec: refs/heads/auto:refs/heads/main
479+ ` ` `
480+
444481# # Update strategy
445482
446483The `.spec.update` field specifies how to carry out updates on the git repository. There is one
0 commit comments