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

Commit

Permalink
Merge branch 'master' into repository-process
Browse files Browse the repository at this point in the history
* master:
  We can't use the name `init`, so let's call it `create`. (#5)
  • Loading branch information
scouten committed Jul 13, 2019
2 parents 152b056 + 6da8d94 commit 601053a
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 12 deletions.
7 changes: 5 additions & 2 deletions lib/xgit/repository/on_disk.ex
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ defmodule Xgit.Repository.OnDisk do
Analogous to [`git init`](https://git-scm.com/docs/git-init).
**NOTE:** We use the name `create` here so as to avoid a naming conflict with
the `GenServer` callback named `init/1`.
## Options
* `:work_dir` (required): Top-level working directory. A `.git` directory is
Expand All @@ -50,6 +53,6 @@ defmodule Xgit.Repository.OnDisk do
Will raise `File.Error` or similar if unable to create the directory.
"""
# @spec init([work_dir: String.t]) :: :ok
defdelegate init(opts), to: Xgit.Repository.OnDisk.Init
@spec create(work_dir: String.t()) :: :ok
defdelegate create(opts), to: Xgit.Repository.OnDisk.Create
end
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
defmodule Xgit.Repository.OnDisk.Init do
defmodule Xgit.Repository.OnDisk.Create do
@moduledoc false
# Implements Xgit.Repository.OnDisk.init/1.
# Implements Xgit.Repository.OnDisk.create/1.

def init(opts) when is_list(opts) do
def create(opts) when is_list(opts) do
work_dir = Keyword.get(opts, :work_dir)

unless is_binary(work_dir) do
raise ArgumentError, "Xgit.Repository.OnDisk.init/1: :work_dir must be a file path"
raise ArgumentError, "Xgit.Repository.OnDisk.create/1: :work_dir must be a file path"
end

work_dir
Expand All @@ -19,7 +19,7 @@ defmodule Xgit.Repository.OnDisk.Init do
defp assert_not_exists!(path) do
if File.exists?(path) do
raise ArgumentError,
"Xgit.Repository.OnDisk.init/1: :work_dir must be a directory that doesn't already exist"
"Xgit.Repository.OnDisk.create/1: :work_dir must be a directory that doesn't already exist"
else
path
end
Expand Down
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
defmodule Xgit.Repository.OnDisk.InitTest do
defmodule Xgit.Repository.OnDisk.CreateTest do
use Xgit.GitInitTestCase, async: true

alias Xgit.Repository.OnDisk

import FolderDiff

describe "init/1" do
describe "create/1" do
test "happy path matches command-line git", %{ref: ref, xgit: xgit} do
assert :ok = OnDisk.init(work_dir: xgit)
assert :ok = OnDisk.create(work_dir: xgit)
assert_folders_are_equal(ref, xgit)
end

test "error: no work_dir" do
assert_raise ArgumentError, fn ->
OnDisk.init([])
OnDisk.create([])
end
end

test "error: work dir exists already", %{xgit: xgit} do
File.mkdir_p!(xgit)

assert_raise ArgumentError, fn ->
OnDisk.init(work_dir: xgit)
OnDisk.create(work_dir: xgit)
end
end
end
Expand Down

0 comments on commit 601053a

Please sign in to comment.