aboutsummaryrefslogtreecommitdiffstats
path: root/pkg/vcs/git_test.go
diff options
context:
space:
mode:
authorAleksandr Nogikh <nogikh@google.com>2024-10-21 17:38:01 +0200
committerTaras Madan <tarasmadan@google.com>2024-10-25 12:08:02 +0000
commitc0390c277e5fcda8d7288b717ff952e01dcdcb8d (patch)
treedec1a2b0e5417c4e1a403c20b3ef3e7d0b95a082 /pkg/vcs/git_test.go
parent500aee76e6243afdb6c953d37e5f1016f73a04cc (diff)
pkg/vcs: parse git diffs
Provide a functionality to extract the files affected by a git patch.
Diffstat (limited to 'pkg/vcs/git_test.go')
-rw-r--r--pkg/vcs/git_test.go22
1 files changed, 22 insertions, 0 deletions
diff --git a/pkg/vcs/git_test.go b/pkg/vcs/git_test.go
index a46408417..daef69501 100644
--- a/pkg/vcs/git_test.go
+++ b/pkg/vcs/git_test.go
@@ -462,3 +462,25 @@ func TestGitFetchShortHash(t *testing.T) {
_, err := local.CheckoutCommit(remoteRepoDir, refCommit.Hash[:12])
assert.NoError(t, err)
}
+
+func TestParseGitDiff(t *testing.T) {
+ files := ParseGitDiff([]byte(`diff --git a/a.txt b/a.txt
+index 4c5fd91..8fe1e32 100644
+--- a/a.txt
++++ b/a.txt
+@@ -1 +1 @@
+-First file
++First file!
+diff --git a/b.txt b/b.txt
+new file mode 100644
+index 0000000..f8a9677
+--- /dev/null
++++ b/b.txt
+@@ -0,0 +1 @@
++Second file.
+diff --git a/c/c.txt b/c/c.txt
+new file mode 100644
+index 0000000..e69de29
+`))
+ assert.ElementsMatch(t, files, []string{"a.txt", "b.txt", "c/c.txt"})
+}