From 9e4d0cb6f6f23b8f22740273cd0f6896e9a75574 Mon Sep 17 00:00:00 2001
From: Nick Thomas <nick@gitlab.com>
Date: Wed, 19 Apr 2017 15:10:07 +0100
Subject: [PATCH] Correctly handle a FROM_SHA value of 000000... (as
 gitlab-rails sets)

Also fix `make setup` to ensure gitlab-test is in a known state
---
 Makefile            | 1 +
 git/go-git.go       | 7 ++-----
 integration_test.go | 7 +++++--
 3 files changed, 8 insertions(+), 7 deletions(-)

diff --git a/Makefile b/Makefile
index 9c8487c..e6468f6 100644
--- a/Makefile
+++ b/Makefile
@@ -90,6 +90,7 @@ setup: clean .GOPATH/.ok
 	- ./bin/gvt fetch github.com/stretchr/testify/assert
 	- mkdir tmp
 	- git clone --bare https://gitlab.com/gitlab-org/gitlab-test.git tmp/gitlab-test.git
+	- git -C tmp/gitlab-test.git update-ref refs/heads/master b83d6e391c22777fca1ed3012fce84f633d7fed0
 
 VERSION          := $(shell git describe --tags --always --dirty="-dev")
 DATE             := $(shell date -u '+%Y-%m-%d-%H%M UTC')
diff --git a/git/go-git.go b/git/go-git.go
index d35289d..a030ba4 100644
--- a/git/go-git.go
+++ b/git/go-git.go
@@ -32,12 +32,9 @@ func NewGoGitRepository(projectPath string, fromSHA string, toSHA string) (*goGi
 		return nil, err
 	}
 	out.Repository = repo
+	out.FromHash = plumbing.NewHash(fromSHA)
 
-	if fromSHA == "" {
-		out.FromHash = plumbing.ZeroHash
-	} else {
-		out.FromHash = plumbing.NewHash(fromSHA)
-
+	if !out.FromHash.IsZero() {
 		commit, err := repo.CommitObject(out.FromHash)
 		if err != nil {
 			return nil, fmt.Errorf("Bad from SHA (%s): %s", out.FromHash, err)
diff --git a/integration_test.go b/integration_test.go
index 651810a..91b34c8 100644
--- a/integration_test.go
+++ b/integration_test.go
@@ -67,10 +67,13 @@ func run(from, to string) error {
 	cmd.Stdout = os.Stdout
 	cmd.Stderr = os.Stderr
 
-	if from != "" {
-		cmd.Env = append(cmd.Env, "FROM_SHA="+from)
+	// GitLab always sets FROM_SHA
+	if from == "" {
+		from = "0000000000000000000000000000000000000000"
 	}
 
+	cmd.Env = append(cmd.Env, "FROM_SHA="+from)
+
 	if to != "" {
 		cmd.Env = append(cmd.Env, "TO_SHA="+to)
 	}
-- 
GitLab