Skip to content
This repository was archived by the owner on Sep 30, 2024. It is now read-only.

Commit d9c9fa8

Browse files
gitserver: change the way repo name is checked for git command recording. (#55111)
Previously, we checked for a substring, but it breaks in cases where given repo name is a prefix for another repo names, e.g.: "repo/a" is included, but "repo/ab" and "repo/a-1" are included too, because of the check. This commit changes this behaviour to check for the suffix instead, which is not perfect, but judging from local testing and how the repos are named ("orgName/repoName"), this check will filter out most repos which were previously included by mistake. Precise implementation requires a lot of effort to propagate repo names through the recording stack and can be done later. Test plan: Local sg run and test that repos with matching prefix are not recorded.
1 parent 1f4dddd commit d9c9fa8

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

cmd/gitserver/shared/shared.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -641,7 +641,11 @@ func recordCommandsOnRepos(repos []string) wrexec.ShouldRecordFunc {
641641

642642
repoMatch := false
643643
for _, repo := range repos {
644-
if strings.Contains(cmd.Dir, repo) {
644+
// We need to check the suffix, because we can have some common parts in
645+
// different repo names. E.g. "sourcegraph/sourcegraph" and
646+
// "sourcegraph/sourcegraph-code-ownership" will both be allowed even if only the
647+
// first name is included in the config.
648+
if strings.HasSuffix(cmd.Dir, repo+"/.git") {
645649
repoMatch = true
646650
break
647651
}

internal/wrexec/recording_cmd.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ type RecordingCmd struct {
3636
done bool
3737
}
3838

39-
// ShouldRecordFunc is a predicate to signifiy if a command should be recorded or just pass through.
39+
// ShouldRecordFunc is a predicate to signify if a command should be recorded or just pass through.
4040
type ShouldRecordFunc func(context.Context, *exec.Cmd) bool
4141

4242
// RecordingCommand contructs a RecordingCommand that implements Cmder. The predicate shouldRecord can be passed to decide on whether

0 commit comments

Comments
 (0)