Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitaly.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Okstad <pokstad@gitlab.com>2019-02-13 01:19:32 +0300
committerPaul Okstad <pokstad@gitlab.com>2019-02-13 01:19:32 +0300
commit3e342ff1f78ccea4390dfab1adbdbc18d4bd96b1 (patch)
tree1a083f37b55605e17f5d7e6314b7f6c8fd0120e4
parent23f32e3ac37a6834debaa1bb9d12ce6e772e44aa (diff)
parenteaaaf99aa439f448bda1eb039c4319ec5d913049 (diff)
Merge branch 'jc-check-for-first-commit' into 'master'
Use empty tree if initial commit See merge request gitlab-org/gitaly!1075
-rw-r--r--changelogs/unreleased/jc-check-for-first-commit.yml5
-rw-r--r--internal/service/commit/stats.go10
-rw-r--r--internal/service/commit/stats_test.go7
3 files changed, 21 insertions, 1 deletions
diff --git a/changelogs/unreleased/jc-check-for-first-commit.yml b/changelogs/unreleased/jc-check-for-first-commit.yml
new file mode 100644
index 000000000..60595e912
--- /dev/null
+++ b/changelogs/unreleased/jc-check-for-first-commit.yml
@@ -0,0 +1,5 @@
+---
+title: Use empty tree if initial commit
+merge_request: 1075
+author:
+type: fixed
diff --git a/internal/service/commit/stats.go b/internal/service/commit/stats.go
index c9b32b171..724b7c05d 100644
--- a/internal/service/commit/stats.go
+++ b/internal/service/commit/stats.go
@@ -35,7 +35,15 @@ func commitStats(ctx context.Context, in *gitalypb.CommitStatsRequest) (*gitalyp
return nil, fmt.Errorf("commit not found: %q", in.Revision)
}
- cmd, err := git.Command(ctx, in.Repository, "diff", "--numstat", commit.Id+"^", commit.Id)
+ args := []string{"diff", "--numstat"}
+
+ if len(commit.GetParentIds()) == 0 {
+ args = append(args, git.EmptyTreeID, commit.Id)
+ } else {
+ args = append(args, commit.Id+"^", commit.Id)
+ }
+
+ cmd, err := git.Command(ctx, in.Repository, args...)
if err != nil {
return nil, err
}
diff --git a/internal/service/commit/stats_test.go b/internal/service/commit/stats_test.go
index 53af68217..f39534730 100644
--- a/internal/service/commit/stats_test.go
+++ b/internal/service/commit/stats_test.go
@@ -58,6 +58,13 @@ func TestCommitStatsSuccess(t *testing.T) {
additions: 0,
deletions: 0,
},
+ {
+ desc: "initial commit",
+ revision: "1a0b36b3",
+ oid: "1a0b36b3cdad1d2ee32457c102a8c0b7056fa863",
+ additions: 43,
+ deletions: 0,
+ },
}
for _, tc := range tests {