Skip to content
This repository has been archived by the owner on Oct 8, 2020. It is now read-only.

Commit

Permalink
Merge c646575 into 342a07c
Browse files Browse the repository at this point in the history
  • Loading branch information
scouten committed Oct 19, 2019
2 parents 342a07c + c646575 commit a842e56
Showing 1 changed file with 69 additions and 2 deletions.
71 changes: 69 additions & 2 deletions test/xgit/core/commit_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,13 @@ defmodule Xgit.Core.CommitTest do
alias Xgit.GitInitTestCase
alias Xgit.Repository
alias Xgit.Repository.OnDisk
alias Xgit.Test.OnDiskRepoTestCase

import FolderDiff

import Xgit.Test.OnDiskRepoTestCase,
only: [setup_with_valid_tree!: 0, setup_with_valid_parent_commit!: 0]

@valid_pi %PersonIdent{
name: "A. U. Thor",
email: "author@example.com",
Expand All @@ -24,6 +28,8 @@ defmodule Xgit.Core.CommitTest do
tz_offset: 150
}

@env OnDiskRepoTestCase.sample_commit_env()

describe "valid?/1" do
test "valid: no parent" do
assert Commit.valid?(%Commit{
Expand Down Expand Up @@ -214,8 +220,69 @@ defmodule Xgit.Core.CommitTest do
end

describe "from_object/1" do
# TO DO: Test ability to read commits generated by command-line git.
# https://github.com/elixir-git/xgit/issues/203
test "command-line interop: no parents" do
%{xgit_path: path, xgit_repo: repo, tree_id: tree_id} = setup_with_valid_tree!()

assert {commit_id_str, 0} =
System.cmd("git", ["commit-tree", tree_id, "-m", "xxx"], cd: path, env: @env)

commit_id = String.trim(commit_id_str)

{:ok, commit_object} = Repository.get_object(repo, commit_id)

assert {:ok,
%Xgit.Core.Commit{
author: %Xgit.Core.PersonIdent{
email: "author@example.com",
name: "A. U. Thor",
tz_offset: 150,
when: 1_142_878_449
},
committer: %Xgit.Core.PersonIdent{
email: "author@example.com",
name: "A. U. Thor",
tz_offset: 150,
when: 1_142_878_449
},
message: 'xxx\n',
parents: [],
tree: "3e69f02f3247843b482cc99872683692999f6703"
}} = Commit.from_object(commit_object)
end

test "command-line interop: one parent" do
%{xgit_path: path, xgit_repo: repo, tree_id: tree_id, parent_id: parent_id} =
setup_with_valid_parent_commit!()

assert {commit_id_str, 0} =
System.cmd("git", ["commit-tree", tree_id, "-m", "mumble", "-p", parent_id],
cd: path,
env: @env
)

commit_id = String.trim(commit_id_str)

{:ok, commit_object} = Repository.get_object(repo, commit_id)

assert {:ok,
%Xgit.Core.Commit{
author: %Xgit.Core.PersonIdent{
email: "author@example.com",
name: "A. U. Thor",
tz_offset: 150,
when: 1_142_878_449
},
committer: %Xgit.Core.PersonIdent{
email: "author@example.com",
name: "A. U. Thor",
tz_offset: 150,
when: 1_142_878_449
},
message: 'mumble\n',
parents: [^parent_id],
tree: "3e69f02f3247843b482cc99872683692999f6703"
}} = Commit.from_object(commit_object)
end

test "valid: no parent" do
assert {:ok,
Expand Down

0 comments on commit a842e56

Please sign in to comment.