Merge pull request #577 from fluxcd/push-options
add support for specifying push options
This commit is contained in:
commit
644ca35fec
|
@ -95,4 +95,10 @@ type PushSpec struct {
|
||||||
// https://git-scm.com/book/en/v2/Git-Internals-The-Refspec
|
// https://git-scm.com/book/en/v2/Git-Internals-The-Refspec
|
||||||
// +optional
|
// +optional
|
||||||
Refspec string `json:"refspec,omitempty"`
|
Refspec string `json:"refspec,omitempty"`
|
||||||
|
|
||||||
|
// Options specifies the push options that are sent to the Git
|
||||||
|
// server when performing a push operation. For details, see:
|
||||||
|
// https://git-scm.com/docs/git-push#Documentation/git-push.txt---push-optionltoptiongt
|
||||||
|
// +optional
|
||||||
|
Options map[string]string `json:"options,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
|
@ -105,7 +105,7 @@ func (in *GitSpec) DeepCopyInto(out *GitSpec) {
|
||||||
if in.Push != nil {
|
if in.Push != nil {
|
||||||
in, out := &in.Push, &out.Push
|
in, out := &in.Push, &out.Push
|
||||||
*out = new(PushSpec)
|
*out = new(PushSpec)
|
||||||
**out = **in
|
(*in).DeepCopyInto(*out)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -239,6 +239,13 @@ func (in *ImageUpdateAutomationStatus) DeepCopy() *ImageUpdateAutomationStatus {
|
||||||
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
|
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
|
||||||
func (in *PushSpec) DeepCopyInto(out *PushSpec) {
|
func (in *PushSpec) DeepCopyInto(out *PushSpec) {
|
||||||
*out = *in
|
*out = *in
|
||||||
|
if in.Options != nil {
|
||||||
|
in, out := &in.Options, &out.Options
|
||||||
|
*out = make(map[string]string, len(*in))
|
||||||
|
for key, val := range *in {
|
||||||
|
(*out)[key] = val
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new PushSpec.
|
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new PushSpec.
|
||||||
|
|
|
@ -135,6 +135,13 @@ spec:
|
||||||
to the branch named. The branch is created using `.spec.checkout.branch`
|
to the branch named. The branch is created using `.spec.checkout.branch`
|
||||||
as the starting point, if it doesn't already exist.
|
as the starting point, if it doesn't already exist.
|
||||||
type: string
|
type: string
|
||||||
|
options:
|
||||||
|
additionalProperties:
|
||||||
|
type: string
|
||||||
|
description: 'Options specifies the push options that are
|
||||||
|
sent to the Git server when performing a push operation.
|
||||||
|
For details, see: https://git-scm.com/docs/git-push#Documentation/git-push.txt---push-optionltoptiongt'
|
||||||
|
type: object
|
||||||
refspec:
|
refspec:
|
||||||
description: 'Refspec specifies the Git Refspec to use for
|
description: 'Refspec specifies the Git Refspec to use for
|
||||||
a push operation. If both Branch and Refspec are provided,
|
a push operation. If both Branch and Refspec are provided,
|
||||||
|
|
|
@ -660,6 +660,20 @@ For more details about Git Refspecs, see:
|
||||||
<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>
|
<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>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>
|
||||||
|
<code>options</code><br>
|
||||||
|
<em>
|
||||||
|
map[string]string
|
||||||
|
</em>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<em>(Optional)</em>
|
||||||
|
<p>Options specifies the push options that are sent to the Git
|
||||||
|
server when performing a push operation. For details, see:
|
||||||
|
<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—push-optionltoptiongt</a></p>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -419,6 +419,11 @@ type PushSpec struct {
|
||||||
// https://git-scm.com/book/en/v2/Git-Internals-The-Refspec
|
// https://git-scm.com/book/en/v2/Git-Internals-The-Refspec
|
||||||
// +optional
|
// +optional
|
||||||
Refspec string `json:"refspec,omitempty"`
|
Refspec string `json:"refspec,omitempty"`
|
||||||
|
|
||||||
|
// Options specifies the push options that are sent to the Git
|
||||||
|
// server when performing a push operation. For details, see:
|
||||||
|
// https://git-scm.com/docs/git-push#Documentation/git-push.txt---push-optionltoptiongt
|
||||||
|
Options map[string]string `json:"options,omitempty"`
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
@ -477,8 +482,23 @@ spec:
|
||||||
refspec: refs/heads/main:refs/heads/auto
|
refspec: refs/heads/main:refs/heads/auto
|
||||||
```
|
```
|
||||||
|
|
||||||
#### Gerrit
|
To specify the [push options](https://git-scm.com/docs/git-push#Documentation/git-push.txt---push-optionltoptiongt)
|
||||||
|
to be sent to the upstream Git server, use `.push.options`. These options can be
|
||||||
|
used to perform operations as a result of the push. For example, using the below
|
||||||
|
push options will open a GitLab Merge Request to the `release` branch
|
||||||
|
automatically with the commit the controller pushed to the `dev` branch:
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
spec:
|
||||||
|
git:
|
||||||
|
push:
|
||||||
|
branch: dev
|
||||||
|
options:
|
||||||
|
merge_request.create: ""
|
||||||
|
merge_request.target: release
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Gerrit
|
||||||
|
|
||||||
[Gerrit](https://www.gerritcodereview.com/) operates differently from a
|
[Gerrit](https://www.gerritcodereview.com/) operates differently from a
|
||||||
standard Git server. Rather than sending individual commits to a branch,
|
standard Git server. Rather than sending individual commits to a branch,
|
||||||
|
|
|
@ -416,11 +416,14 @@ func (r *ImageUpdateAutomationReconciler) Reconcile(ctx context.Context, req ctr
|
||||||
pushToBranch = true
|
pushToBranch = true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var pushConfig repository.PushConfig
|
||||||
|
if gitSpec.Push != nil {
|
||||||
|
pushConfig.Options = gitSpec.Push.Options
|
||||||
|
}
|
||||||
if pushToBranch {
|
if pushToBranch {
|
||||||
// If the force push feature flag is true and we are pushing to a
|
// If the force push feature flag is true and we are pushing to a
|
||||||
// different branch than the one we checked out to, then force push
|
// different branch than the one we checked out to, then force push
|
||||||
// these changes.
|
// these changes.
|
||||||
var pushConfig repository.PushConfig
|
|
||||||
forcePush := r.features[features.GitForcePushBranch]
|
forcePush := r.features[features.GitForcePushBranch]
|
||||||
if forcePush && switchBranch {
|
if forcePush && switchBranch {
|
||||||
pushConfig.Force = true
|
pushConfig.Force = true
|
||||||
|
@ -434,9 +437,7 @@ func (r *ImageUpdateAutomationReconciler) Reconcile(ctx context.Context, req ctr
|
||||||
}
|
}
|
||||||
|
|
||||||
if pushWithRefspec {
|
if pushWithRefspec {
|
||||||
pushConfig := repository.PushConfig{
|
pushConfig.Refspecs = []string{gitSpec.Push.Refspec}
|
||||||
Refspecs: []string{gitSpec.Push.Refspec},
|
|
||||||
}
|
|
||||||
if err := gitClient.Push(pushCtx, pushConfig); err != nil {
|
if err := gitClient.Push(pushCtx, pushConfig); err != nil {
|
||||||
return failWithError(err)
|
return failWithError(err)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue