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

We can't use the name init, so let's call it create. #5

Merged
merged 1 commit into from
Jul 13, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions lib/xgit/repository/on_disk.ex
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,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 @@ -30,6 +33,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