aboutsummaryrefslogtreecommitdiffstats
path: root/modules
diff options
context:
space:
mode:
authorLaurent Cahour <laurent.cahour@dont-nod.com>2023-08-24 12:03:49 +0200
committerGitHub <noreply@github.com>2023-08-24 10:03:49 +0000
commitb21b63c61ac1038a1597acee45084896f5e39a3a (patch)
tree0cf90d2f28448c40590c31f020e85e3903c0c857 /modules
parent86ee5b4b1b6acdba89912a3c89c39f9948e67f07 (diff)
downloadgitea-b21b63c61ac1038a1597acee45084896f5e39a3a.tar.gz
gitea-b21b63c61ac1038a1597acee45084896f5e39a3a.zip
Add merge files files to GetCommitFileStatus (#20515)
Hi, We'd like to add merge files files to GetCommitFileStatus fucntions so API returns the list of all the files associated to a merged pull request commit, like GitHub API does. The list of affectedFiles for an API commit is fetched from toCommit() function in routers/api/v1/repo/commits.go, and API was returning no file in case of a pull request with no conflict, or just files associated to the confict resolution, but NOT the full list of merged files. This would lead to situations where a CI polling a repo for changes could miss some file changes due to API returning an empty / partial list in case of such merged pull requests. (Hope this makes sense :) ) NOTE: I'd like to add a unittest in integrations/api_repo_git_commits_test.go but failed to understand how to add my own test bare repo so I can make a test on a merged pull request commit to check for affectedFiles. Is there a merged pull request in there that I could use maybe? Could someone please direct me to the relevant ressources with informations on how to do that please? Thanks for your time, Laurent. --------- Co-authored-by: Thomas Desveaux <desveaux.thomas@gmail.com>
Diffstat (limited to 'modules')
-rw-r--r--modules/git/commit.go2
-rw-r--r--modules/git/commit_test.go23
-rw-r--r--modules/git/tests/repos/repo6_merge/HEAD1
-rw-r--r--modules/git/tests/repos/repo6_merge/objects/02/2f4ce6214973e018f02bf363bf8a2e3691f699bin0 -> 280 bytes
-rw-r--r--modules/git/tests/repos/repo6_merge/objects/05/45879290cc368a8becebc4aa34002c52d5feccbin0 -> 152 bytes
-rw-r--r--modules/git/tests/repos/repo6_merge/objects/1e/5d0a65fe099ef12d24b28f783896e4b8172576bin0 -> 88 bytes
-rw-r--r--modules/git/tests/repos/repo6_merge/objects/37/d35c7ed39e4e16d0b579a5b995b7e30b0e94112
-rw-r--r--modules/git/tests/repos/repo6_merge/objects/38/ec3e0cdc88bde01014bda4a5dd9fc835f414392
-rw-r--r--modules/git/tests/repos/repo6_merge/objects/66/7e0fbc6bc02c2285d17f542e89b23c0fa5482bbin0 -> 122 bytes
-rw-r--r--modules/git/tests/repos/repo6_merge/objects/9f/d90b1d524c0fea776ed5e6476da02ea1740597bin0 -> 26 bytes
-rw-r--r--modules/git/tests/repos/repo6_merge/objects/ae/4b035e7c4afbc000576cee3f713ea0c2f1e1e25
-rw-r--r--modules/git/tests/repos/repo6_merge/objects/ba/2906d0666cf726c7eaadd2cd3db615dedfdf3abin0 -> 20 bytes
-rw-r--r--modules/git/tests/repos/repo6_merge/objects/c1/a95c2eff8151c6d1437a0d5d3322a73ff38fb8bin0 -> 120 bytes
-rw-r--r--modules/git/tests/repos/repo6_merge/objects/cc/d1d4d594029e68c388ecef5aa3063fa1055831bin0 -> 26 bytes
-rw-r--r--modules/git/tests/repos/repo6_merge/objects/cd/fc1aaf7a149151cb7bff639fafe05668d4bbd2bin0 -> 120 bytes
-rw-r--r--modules/git/tests/repos/repo6_merge/objects/d1/792641396ff7630d35fbb0b74b86b0c71bca77bin0 -> 145 bytes
-rw-r--r--modules/git/tests/repos/repo6_merge/objects/ec/d11d8da0f25eaa99f64a37a82da98685f381e2bin0 -> 33 bytes
-rw-r--r--modules/git/tests/repos/repo6_merge/objects/fa/49b077972391ad58037050f2a75f74e3671e92bin0 -> 24 bytes
-rw-r--r--modules/git/tests/repos/repo6_merge/refs/heads/main1
-rw-r--r--modules/git/tests/repos/repo6_merge/refs/heads/merge/add_file1
-rw-r--r--modules/git/tests/repos/repo6_merge/refs/heads/merge/modify_file1
-rw-r--r--modules/git/tests/repos/repo6_merge/refs/heads/merge/remove_file1
22 files changed, 38 insertions, 1 deletions
diff --git a/modules/git/commit.go b/modules/git/commit.go
index c44882d886..b09be25ba0 100644
--- a/modules/git/commit.go
+++ b/modules/git/commit.go
@@ -495,7 +495,7 @@ func GetCommitFileStatus(ctx context.Context, repoPath, commitID string) (*Commi
}()
stderr := new(bytes.Buffer)
- err := NewCommand(ctx, "log", "--name-status", "-c", "--pretty=format:", "--parents", "--no-renames", "-z", "-1").AddDynamicArguments(commitID).Run(&RunOpts{
+ err := NewCommand(ctx, "log", "--name-status", "-m", "--pretty=format:", "--first-parent", "--no-renames", "-z", "-1").AddDynamicArguments(commitID).Run(&RunOpts{
Dir: repoPath,
Stdout: w,
Stderr: stderr,
diff --git a/modules/git/commit_test.go b/modules/git/commit_test.go
index acf4beb029..ac586fdf09 100644
--- a/modules/git/commit_test.go
+++ b/modules/git/commit_test.go
@@ -255,3 +255,26 @@ func TestParseCommitFileStatus(t *testing.T) {
assert.Equal(t, kase.modified, fileStatus.Modified)
}
}
+
+func TestGetCommitFileStatusMerges(t *testing.T) {
+ bareRepo1Path := filepath.Join(testReposDir, "repo6_merge")
+
+ commitFileStatus, err := GetCommitFileStatus(DefaultContext, bareRepo1Path, "022f4ce6214973e018f02bf363bf8a2e3691f699")
+ assert.NoError(t, err)
+
+ expected := CommitFileStatus{
+ []string{
+ "add_file.txt",
+ },
+ []string{
+ "to_remove.txt",
+ },
+ []string{
+ "to_modify.txt",
+ },
+ }
+
+ assert.Equal(t, commitFileStatus.Added, expected.Added)
+ assert.Equal(t, commitFileStatus.Removed, expected.Removed)
+ assert.Equal(t, commitFileStatus.Modified, expected.Modified)
+}
diff --git a/modules/git/tests/repos/repo6_merge/HEAD b/modules/git/tests/repos/repo6_merge/HEAD
new file mode 100644
index 0000000000..b870d82622
--- /dev/null
+++ b/modules/git/tests/repos/repo6_merge/HEAD
@@ -0,0 +1 @@
+ref: refs/heads/main
diff --git a/modules/git/tests/repos/repo6_merge/objects/02/2f4ce6214973e018f02bf363bf8a2e3691f699 b/modules/git/tests/repos/repo6_merge/objects/02/2f4ce6214973e018f02bf363bf8a2e3691f699
new file mode 100644
index 0000000000..0778a1c88c
--- /dev/null
+++ b/modules/git/tests/repos/repo6_merge/objects/02/2f4ce6214973e018f02bf363bf8a2e3691f699
Binary files differ
diff --git a/modules/git/tests/repos/repo6_merge/objects/05/45879290cc368a8becebc4aa34002c52d5fecc b/modules/git/tests/repos/repo6_merge/objects/05/45879290cc368a8becebc4aa34002c52d5fecc
new file mode 100644
index 0000000000..c71794f329
--- /dev/null
+++ b/modules/git/tests/repos/repo6_merge/objects/05/45879290cc368a8becebc4aa34002c52d5fecc
Binary files differ
diff --git a/modules/git/tests/repos/repo6_merge/objects/1e/5d0a65fe099ef12d24b28f783896e4b8172576 b/modules/git/tests/repos/repo6_merge/objects/1e/5d0a65fe099ef12d24b28f783896e4b8172576
new file mode 100644
index 0000000000..365f368d35
--- /dev/null
+++ b/modules/git/tests/repos/repo6_merge/objects/1e/5d0a65fe099ef12d24b28f783896e4b8172576
Binary files differ
diff --git a/modules/git/tests/repos/repo6_merge/objects/37/d35c7ed39e4e16d0b579a5b995b7e30b0e9411 b/modules/git/tests/repos/repo6_merge/objects/37/d35c7ed39e4e16d0b579a5b995b7e30b0e9411
new file mode 100644
index 0000000000..83890b5d0b
--- /dev/null
+++ b/modules/git/tests/repos/repo6_merge/objects/37/d35c7ed39e4e16d0b579a5b995b7e30b0e9411
@@ -0,0 +1,2 @@
+xM
+1 a=E$LAī'iRg~_u1N@mZ)g2Dj*_fs 4amnp>>!#1;p]xuyIwN4 \ No newline at end of file
diff --git a/modules/git/tests/repos/repo6_merge/objects/38/ec3e0cdc88bde01014bda4a5dd9fc835f41439 b/modules/git/tests/repos/repo6_merge/objects/38/ec3e0cdc88bde01014bda4a5dd9fc835f41439
new file mode 100644
index 0000000000..582d98ce30
--- /dev/null
+++ b/modules/git/tests/repos/repo6_merge/objects/38/ec3e0cdc88bde01014bda4a5dd9fc835f41439
@@ -0,0 +1,2 @@
+xM
+0a9M2 U =yv/ 0:@$UѬ.[> lIsx 8'TRĤS,$x. ֚=n[נus!+9BGvfm ur> \ No newline at end of file
diff --git a/modules/git/tests/repos/repo6_merge/objects/66/7e0fbc6bc02c2285d17f542e89b23c0fa5482b b/modules/git/tests/repos/repo6_merge/objects/66/7e0fbc6bc02c2285d17f542e89b23c0fa5482b
new file mode 100644
index 0000000000..d7faff6bf2
--- /dev/null
+++ b/modules/git/tests/repos/repo6_merge/objects/66/7e0fbc6bc02c2285d17f542e89b23c0fa5482b
Binary files differ
diff --git a/modules/git/tests/repos/repo6_merge/objects/9f/d90b1d524c0fea776ed5e6476da02ea1740597 b/modules/git/tests/repos/repo6_merge/objects/9f/d90b1d524c0fea776ed5e6476da02ea1740597
new file mode 100644
index 0000000000..8ac2814c0f
--- /dev/null
+++ b/modules/git/tests/repos/repo6_merge/objects/9f/d90b1d524c0fea776ed5e6476da02ea1740597
Binary files differ
diff --git a/modules/git/tests/repos/repo6_merge/objects/ae/4b035e7c4afbc000576cee3f713ea0c2f1e1e2 b/modules/git/tests/repos/repo6_merge/objects/ae/4b035e7c4afbc000576cee3f713ea0c2f1e1e2
new file mode 100644
index 0000000000..c0f6b1334f
--- /dev/null
+++ b/modules/git/tests/repos/repo6_merge/objects/ae/4b035e7c4afbc000576cee3f713ea0c2f1e1e2
@@ -0,0 +1,5 @@
+xM
+1 @a=E?i*mǑxO=x.lORZ80\[*%b
+&q IȚ灝
+7ԋF쨜wcuzx?0
+1 :m6LS>& \ No newline at end of file
diff --git a/modules/git/tests/repos/repo6_merge/objects/ba/2906d0666cf726c7eaadd2cd3db615dedfdf3a b/modules/git/tests/repos/repo6_merge/objects/ba/2906d0666cf726c7eaadd2cd3db615dedfdf3a
new file mode 100644
index 0000000000..edef2a7f0c
--- /dev/null
+++ b/modules/git/tests/repos/repo6_merge/objects/ba/2906d0666cf726c7eaadd2cd3db615dedfdf3a
Binary files differ
diff --git a/modules/git/tests/repos/repo6_merge/objects/c1/a95c2eff8151c6d1437a0d5d3322a73ff38fb8 b/modules/git/tests/repos/repo6_merge/objects/c1/a95c2eff8151c6d1437a0d5d3322a73ff38fb8
new file mode 100644
index 0000000000..353d86ccdb
--- /dev/null
+++ b/modules/git/tests/repos/repo6_merge/objects/c1/a95c2eff8151c6d1437a0d5d3322a73ff38fb8
Binary files differ
diff --git a/modules/git/tests/repos/repo6_merge/objects/cc/d1d4d594029e68c388ecef5aa3063fa1055831 b/modules/git/tests/repos/repo6_merge/objects/cc/d1d4d594029e68c388ecef5aa3063fa1055831
new file mode 100644
index 0000000000..5449d726cd
--- /dev/null
+++ b/modules/git/tests/repos/repo6_merge/objects/cc/d1d4d594029e68c388ecef5aa3063fa1055831
Binary files differ
diff --git a/modules/git/tests/repos/repo6_merge/objects/cd/fc1aaf7a149151cb7bff639fafe05668d4bbd2 b/modules/git/tests/repos/repo6_merge/objects/cd/fc1aaf7a149151cb7bff639fafe05668d4bbd2
new file mode 100644
index 0000000000..030eb980f6
--- /dev/null
+++ b/modules/git/tests/repos/repo6_merge/objects/cd/fc1aaf7a149151cb7bff639fafe05668d4bbd2
Binary files differ
diff --git a/modules/git/tests/repos/repo6_merge/objects/d1/792641396ff7630d35fbb0b74b86b0c71bca77 b/modules/git/tests/repos/repo6_merge/objects/d1/792641396ff7630d35fbb0b74b86b0c71bca77
new file mode 100644
index 0000000000..867e4c0b86
--- /dev/null
+++ b/modules/git/tests/repos/repo6_merge/objects/d1/792641396ff7630d35fbb0b74b86b0c71bca77
Binary files differ
diff --git a/modules/git/tests/repos/repo6_merge/objects/ec/d11d8da0f25eaa99f64a37a82da98685f381e2 b/modules/git/tests/repos/repo6_merge/objects/ec/d11d8da0f25eaa99f64a37a82da98685f381e2
new file mode 100644
index 0000000000..52d300cdf1
--- /dev/null
+++ b/modules/git/tests/repos/repo6_merge/objects/ec/d11d8da0f25eaa99f64a37a82da98685f381e2
Binary files differ
diff --git a/modules/git/tests/repos/repo6_merge/objects/fa/49b077972391ad58037050f2a75f74e3671e92 b/modules/git/tests/repos/repo6_merge/objects/fa/49b077972391ad58037050f2a75f74e3671e92
new file mode 100644
index 0000000000..112998d425
--- /dev/null
+++ b/modules/git/tests/repos/repo6_merge/objects/fa/49b077972391ad58037050f2a75f74e3671e92
Binary files differ
diff --git a/modules/git/tests/repos/repo6_merge/refs/heads/main b/modules/git/tests/repos/repo6_merge/refs/heads/main
new file mode 100644
index 0000000000..adf9e86717
--- /dev/null
+++ b/modules/git/tests/repos/repo6_merge/refs/heads/main
@@ -0,0 +1 @@
+022f4ce6214973e018f02bf363bf8a2e3691f699
diff --git a/modules/git/tests/repos/repo6_merge/refs/heads/merge/add_file b/modules/git/tests/repos/repo6_merge/refs/heads/merge/add_file
new file mode 100644
index 0000000000..035ad11863
--- /dev/null
+++ b/modules/git/tests/repos/repo6_merge/refs/heads/merge/add_file
@@ -0,0 +1 @@
+ae4b035e7c4afbc000576cee3f713ea0c2f1e1e2
diff --git a/modules/git/tests/repos/repo6_merge/refs/heads/merge/modify_file b/modules/git/tests/repos/repo6_merge/refs/heads/merge/modify_file
new file mode 100644
index 0000000000..f0d5105f54
--- /dev/null
+++ b/modules/git/tests/repos/repo6_merge/refs/heads/merge/modify_file
@@ -0,0 +1 @@
+d1792641396ff7630d35fbb0b74b86b0c71bca77
diff --git a/modules/git/tests/repos/repo6_merge/refs/heads/merge/remove_file b/modules/git/tests/repos/repo6_merge/refs/heads/merge/remove_file
new file mode 100644
index 0000000000..ada3c8b3f4
--- /dev/null
+++ b/modules/git/tests/repos/repo6_merge/refs/heads/merge/remove_file
@@ -0,0 +1 @@
+38ec3e0cdc88bde01014bda4a5dd9fc835f41439