Skip to content

Commit 4789cbf

Browse files
check there are not 2+ lines
Signed-off-by: Tim Vaillancourt <[email protected]>
1 parent 3063138 commit 4789cbf

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

test/ci_workflow_gen.go

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -237,15 +237,19 @@ func getGitRefSHA(ctx context.Context, url, branchOrTag string) (string, error)
237237
return "", err
238238
}
239239

240-
// git ls-remote returns two text columns: a commit SHA and a reference.
240+
// 'git ls-remote <url> <branchOrTag>' returns two text columns: a commit
241+
// SHA and a reference. We expect the stdout to be a single line, which
242+
// should always be true (but we still validate).
241243
// Example:
242244
// $ git ls-remote https://github.com/vitessio/go-junit-report HEAD
243245
// 99fa7f0daf16db969f54a49139a14471e633e6e8 HEAD
244-
fields := strings.Fields(stdout.String())
245-
if len(fields) != 2 {
246-
return "", fmt.Errorf("cannot parse output of 'git ls-remote' for %q", url)
246+
for line := range strings.Lines(stdout.String()) {
247+
fields := strings.Fields(line)
248+
if len(fields) == 2 {
249+
return fields[0], nil
250+
}
247251
}
248-
return fields[0], nil
252+
return "", fmt.Errorf("cannot parse output of 'git ls-remote' for %q", url)
249253
}
250254

251255
// getGitMetas concurrently fetches Git metadata for workflow dependencies.

0 commit comments

Comments
 (0)