diff options
author | Jacob Vosmaer (GitLab) <jacob@gitlab.com> | 2017-12-22 18:19:44 +0300 |
---|---|---|
committer | Ahmad Sherif <ahmad.m.sherif@gmail.com> | 2017-12-22 18:19:44 +0300 |
commit | 40956c57717298675c91ea291b3d768c30a2f140 (patch) | |
tree | 4fa6a425070ac3c0948360cd440da2f950693b34 /internal/testhelper | |
parent | b9d2522cb80e798c6084d30ebcfec7edb8771988 (diff) |
Handle failed merge when branch gets updated
Diffstat (limited to 'internal/testhelper')
-rw-r--r-- | internal/testhelper/commit.go | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/internal/testhelper/commit.go b/internal/testhelper/commit.go new file mode 100644 index 000000000..5d3cca8da --- /dev/null +++ b/internal/testhelper/commit.go @@ -0,0 +1,22 @@ +package testhelper + +import ( + "strings" + "testing" +) + +// CreateCommit makes a new empty commit and updates the named branch to point to it. +func CreateCommit(t *testing.T, repoPath string, branchName string) string { + // The ID of an arbitrary commit known to exist in the test repository. + parentID := "1a0b36b3cdad1d2ee32457c102a8c0b7056fa863" + + // Use 'commit-tree' instead of 'commit' because we are in a bare + // repository. What we do here is the same as "commit -m message + // --allow-empty". + commitArgs := []string{"-C", repoPath, "commit-tree", "-m", "message", "-p", parentID, parentID + "^{tree}"} + newCommit := MustRunCommand(t, nil, "git", commitArgs...) + newCommitID := strings.TrimSpace(string(newCommit)) + + MustRunCommand(t, nil, "git", "-C", repoPath, "update-ref", "refs/heads/"+branchName, newCommitID) + return newCommitID +} |