Skip to content

Commit 644ca35

Browse files
authored
Merge pull request #577 from fluxcd/push-options
add support for specifying push options
2 parents 1e0fad1 + 1dd0e63 commit 644ca35

File tree

6 files changed

+61
-6
lines changed

6 files changed

+61
-6
lines changed

api/v1beta1/git.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,4 +95,10 @@ type PushSpec struct {
9595
// https://git-scm.com/book/en/v2/Git-Internals-The-Refspec
9696
// +optional
9797
Refspec string `json:"refspec,omitempty"`
98+
99+
// Options specifies the push options that are sent to the Git
100+
// server when performing a push operation. For details, see:
101+
// https://git-scm.com/docs/git-push#Documentation/git-push.txt---push-optionltoptiongt
102+
// +optional
103+
Options map[string]string `json:"options,omitempty"`
98104
}

api/v1beta1/zz_generated.deepcopy.go

Lines changed: 8 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

config/crd/bases/image.toolkit.fluxcd.io_imageupdateautomations.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,13 @@ spec:
135135
to the branch named. The branch is created using `.spec.checkout.branch`
136136
as the starting point, if it doesn't already exist.
137137
type: string
138+
options:
139+
additionalProperties:
140+
type: string
141+
description: 'Options specifies the push options that are
142+
sent to the Git server when performing a push operation.
143+
For details, see: https://git-scm.com/docs/git-push#Documentation/git-push.txt---push-optionltoptiongt'
144+
type: object
138145
refspec:
139146
description: 'Refspec specifies the Git Refspec to use for
140147
a push operation. If both Branch and Refspec are provided,

docs/api/v1beta1/image-automation.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -660,6 +660,20 @@ For more details about Git Refspecs, see:
660660
<a href="https://git-scm.com/book/en/v2/Git-Internals-The-Refspec">https://git-scm.com/book/en/v2/Git-Internals-The-Refspec</a></p>
661661
</td>
662662
</tr>
663+
<tr>
664+
<td>
665+
<code>options</code><br>
666+
<em>
667+
map[string]string
668+
</em>
669+
</td>
670+
<td>
671+
<em>(Optional)</em>
672+
<p>Options specifies the push options that are sent to the Git
673+
server when performing a push operation. For details, see:
674+
<a href="https://git-scm.com/docs/git-push#Documentation/git-push.txt---push-optionltoptiongt">https://git-scm.com/docs/git-push#Documentation/git-push.txt&mdash;push-optionltoptiongt</a></p>
675+
</td>
676+
</tr>
663677
</tbody>
664678
</table>
665679
</div>

docs/spec/v1beta1/imageupdateautomations.md

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -419,6 +419,11 @@ type PushSpec struct {
419419
// https://git-scm.com/book/en/v2/Git-Internals-The-Refspec
420420
// +optional
421421
Refspec string `json:"refspec,omitempty"`
422+
423+
// Options specifies the push options that are sent to the Git
424+
// server when performing a push operation. For details, see:
425+
// https://git-scm.com/docs/git-push#Documentation/git-push.txt---push-optionltoptiongt
426+
Options map[string]string `json:"options,omitempty"`
422427
}
423428
```
424429

@@ -477,8 +482,23 @@ spec:
477482
refspec: refs/heads/main:refs/heads/auto
478483
```
479484

480-
#### Gerrit
485+
To specify the [push options](https://git-scm.com/docs/git-push#Documentation/git-push.txt---push-optionltoptiongt)
486+
to be sent to the upstream Git server, use `.push.options`. These options can be
487+
used to perform operations as a result of the push. For example, using the below
488+
push options will open a GitLab Merge Request to the `release` branch
489+
automatically with the commit the controller pushed to the `dev` branch:
481490

491+
```yaml
492+
spec:
493+
git:
494+
push:
495+
branch: dev
496+
options:
497+
merge_request.create: ""
498+
merge_request.target: release
499+
```
500+
501+
#### Gerrit
482502

483503
[Gerrit](https://www.gerritcodereview.com/) operates differently from a
484504
standard Git server. Rather than sending individual commits to a branch,

internal/controller/imageupdateautomation_controller.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -416,11 +416,14 @@ func (r *ImageUpdateAutomationReconciler) Reconcile(ctx context.Context, req ctr
416416
pushToBranch = true
417417
}
418418

419+
var pushConfig repository.PushConfig
420+
if gitSpec.Push != nil {
421+
pushConfig.Options = gitSpec.Push.Options
422+
}
419423
if pushToBranch {
420424
// If the force push feature flag is true and we are pushing to a
421425
// different branch than the one we checked out to, then force push
422426
// these changes.
423-
var pushConfig repository.PushConfig
424427
forcePush := r.features[features.GitForcePushBranch]
425428
if forcePush && switchBranch {
426429
pushConfig.Force = true
@@ -434,9 +437,7 @@ func (r *ImageUpdateAutomationReconciler) Reconcile(ctx context.Context, req ctr
434437
}
435438

436439
if pushWithRefspec {
437-
pushConfig := repository.PushConfig{
438-
Refspecs: []string{gitSpec.Push.Refspec},
439-
}
440+
pushConfig.Refspecs = []string{gitSpec.Push.Refspec}
440441
if err := gitClient.Push(pushCtx, pushConfig); err != nil {
441442
return failWithError(err)
442443
}

0 commit comments

Comments
 (0)