@@ -133,24 +133,18 @@ type changeWriter func(app *v1alpha1.Application, wbc *WriteBackConfig, gitC git
133
133
// It first checks for a branch specified in annotations, then uses the
134
134
// targetRevision from the matching git source, falling back to getApplicationSource.
135
135
func getWriteBackBranch (app * v1alpha1.Application ) string {
136
- // First check if branch is explicitly set in annotations
137
- annotations := app .GetAnnotations ()
138
- if branch , ok := annotations [common .GitBranchAnnotation ]; ok {
139
- return branch
140
- }
141
-
142
- logCtx := log .WithContext ().AddField ("application" , app .GetName ())
143
-
144
136
// If git repository is specified, find matching source
145
- if gitRepo , ok := annotations [common .GitRepositoryAnnotation ]; ok {
137
+ if gitRepo , ok := app . GetAnnotations () [common .GitRepositoryAnnotation ]; ok {
146
138
if app .Spec .HasMultipleSources () {
147
139
for _ , s := range app .Spec .Sources {
148
140
if s .RepoURL == gitRepo {
149
- logCtx .Debugf ("Found matching source for git repository %s" , gitRepo )
141
+ log .WithContext ().AddField ("application" , app .GetName ()).
142
+ Debugf ("Using target revision '%s' from matching source '%s'" , s .TargetRevision , gitRepo )
150
143
return s .TargetRevision
151
144
}
152
145
}
153
- logCtx .Debugf ("No matching source found for git repository %s, falling back to getApplicationSource" , gitRepo )
146
+ log .WithContext ().AddField ("application" , app .GetName ()).
147
+ Debugf ("No matching source found for git repository %s, falling back to primary source" , gitRepo )
154
148
}
155
149
}
156
150
@@ -195,9 +189,11 @@ func commitChangesGit(app *v1alpha1.Application, wbc *WriteBackConfig, changeLis
195
189
// config, or taken from the application spec's targetRevision. If the
196
190
// target revision is set to the special value HEAD, or is the empty
197
191
// string, we'll try to resolve it to a branch name.
198
- checkOutBranch := getWriteBackBranch ( app )
192
+ var checkOutBranch string
199
193
if wbc .GitBranch != "" {
200
194
checkOutBranch = wbc .GitBranch
195
+ } else {
196
+ checkOutBranch = getWriteBackBranch (app )
201
197
}
202
198
logCtx .Tracef ("targetRevision for update is '%s'" , checkOutBranch )
203
199
if checkOutBranch == "" || checkOutBranch == "HEAD" {
0 commit comments