diff options
| author | Aleksandr Nogikh <nogikh@google.com> | 2024-10-21 17:38:01 +0200 |
|---|---|---|
| committer | Taras Madan <tarasmadan@google.com> | 2024-10-25 12:08:02 +0000 |
| commit | c0390c277e5fcda8d7288b717ff952e01dcdcb8d (patch) | |
| tree | dec1a2b0e5417c4e1a403c20b3ef3e7d0b95a082 /pkg/vcs/git.go | |
| parent | 500aee76e6243afdb6c953d37e5f1016f73a04cc (diff) | |
pkg/vcs: parse git diffs
Provide a functionality to extract the files affected by a git patch.
Diffstat (limited to 'pkg/vcs/git.go')
| -rw-r--r-- | pkg/vcs/git.go | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/pkg/vcs/git.go b/pkg/vcs/git.go index 7425066d2..b75859338 100644 --- a/pkg/vcs/git.go +++ b/pkg/vcs/git.go @@ -654,3 +654,14 @@ func (git *git) PushCommit(repo, commit string) error { } return nil } + +var fileNameRe = regexp.MustCompile(`(?m)^diff.* b\/([^\s]+)`) + +// ParseGitDiff extracts the files modified in the git patch. +func ParseGitDiff(patch []byte) []string { + var files []string + for _, match := range fileNameRe.FindAllStringSubmatch(string(patch), -1) { + files = append(files, match[1]) + } + return files +} |
