Skip to content

Commit 101af51

Browse files
committed
resolve issues
Signed-off-by: Atif Ali <atali@redhat.com>
1 parent 81250b7 commit 101af51

File tree

1 file changed

+8
-12
lines changed

1 file changed

+8
-12
lines changed

pkg/argocd/git.go

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -133,24 +133,18 @@ type changeWriter func(app *v1alpha1.Application, wbc *WriteBackConfig, gitC git
133133
// It first checks for a branch specified in annotations, then uses the
134134
// targetRevision from the matching git source, falling back to getApplicationSource.
135135
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-
144136
// 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 {
146138
if app.Spec.HasMultipleSources() {
147139
for _, s := range app.Spec.Sources {
148140
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)
150143
return s.TargetRevision
151144
}
152145
}
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)
154148
}
155149
}
156150

@@ -195,9 +189,11 @@ func commitChangesGit(app *v1alpha1.Application, wbc *WriteBackConfig, changeLis
195189
// config, or taken from the application spec's targetRevision. If the
196190
// target revision is set to the special value HEAD, or is the empty
197191
// string, we'll try to resolve it to a branch name.
198-
checkOutBranch := getWriteBackBranch(app)
192+
var checkOutBranch string
199193
if wbc.GitBranch != "" {
200194
checkOutBranch = wbc.GitBranch
195+
} else {
196+
checkOutBranch = getWriteBackBranch(app)
201197
}
202198
logCtx.Tracef("targetRevision for update is '%s'", checkOutBranch)
203199
if checkOutBranch == "" || checkOutBranch == "HEAD" {

0 commit comments

Comments
 (0)