diff options
author | John Cai <jcai@gitlab.com> | 2019-01-04 17:56:05 +0300 |
---|---|---|
committer | Jacob Vosmaer <jacob@gitlab.com> | 2019-01-04 17:56:05 +0300 |
commit | 3fef513cfcfd465f753e4f5f9649b4f9e7692597 (patch) | |
tree | 5e9b9d1e79037e1e5d4040bc53e2e949ada48707 /internal/git/updateref | |
parent | c3dfc0b4d5cdcc24b15c05c5f32aa6f549991d0c (diff) |
Migrate writeref from using the ruby implementation to go
Diffstat (limited to 'internal/git/updateref')
-rw-r--r-- | internal/git/updateref/updateref.go | 4 | ||||
-rw-r--r-- | internal/git/updateref/updateref_test.go | 13 |
2 files changed, 14 insertions, 3 deletions
diff --git a/internal/git/updateref/updateref.go b/internal/git/updateref/updateref.go index c61cc7e62..01376be52 100644 --- a/internal/git/updateref/updateref.go +++ b/internal/git/updateref/updateref.go @@ -40,8 +40,8 @@ func (u *Updater) Create(ref, value string) error { // Update commands the reference to be updated to point at the sha specified in // newvalue -func (u *Updater) Update(ref, newvalue string) error { - _, err := fmt.Fprintf(u.cmd, "update %s\x00%s\x00\x00", ref, newvalue) +func (u *Updater) Update(ref, newvalue, oldvalue string) error { + _, err := fmt.Fprintf(u.cmd, "update %s\x00%s\x00%s\x00", ref, newvalue, oldvalue) return err } diff --git a/internal/git/updateref/updateref_test.go b/internal/git/updateref/updateref_test.go index 1fb9aefb8..3de350b25 100644 --- a/internal/git/updateref/updateref_test.go +++ b/internal/git/updateref/updateref_test.go @@ -66,7 +66,7 @@ func TestUpdate(t *testing.T) { require.NotNil(t, commit, "%s does not exist in the test repository", ref) require.NotEqual(t, commit.Id, sha, "%s points to HEAD: %s in the test repository", ref, sha) - require.NoError(t, updater.Update(ref, sha)) + require.NoError(t, updater.Update(ref, sha, "")) require.NoError(t, updater.Wait()) // check the ref was updated @@ -74,6 +74,17 @@ func TestUpdate(t *testing.T) { require.NoError(t, logErr) require.NotNil(t, commit) require.Equal(t, commit.Id, sha, "reference was not updated") + + // since ref has been updated to HEAD, we know that it does not point to HEAD^. So, HEAD^ is an invalid "old value" for updating ref + parentCommit, err := log.GetCommit(ctx, testRepo, "HEAD^") + require.NoError(t, err) + require.Error(t, updater.Update(ref, parentCommit.Id, parentCommit.Id)) + + // check the ref was not updated + commit, logErr = log.GetCommit(ctx, testRepo, ref) + require.NoError(t, logErr) + require.NotNil(t, commit) + require.NotEqual(t, commit.Id, parentCommit.Id, "reference was updated when it shouldn't have been") } func TestDelete(t *testing.T) { |