This repository has been archived by the owner on Oct 8, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Share code for finding working tree in plumbing command modules. (#134)
- Loading branch information
Showing
3 changed files
with
40 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
defmodule Xgit.Plumbing.Util.WorkingTreeOpt do | ||
@moduledoc false | ||
# For use by plumbing modules only. | ||
|
||
alias Xgit.Repository | ||
alias Xgit.Repository.WorkingTree | ||
|
||
# Parse working tree and repository from arguments and options. | ||
|
||
@spec get(repository :: Repository.t(), working_tree: WorkingTree.t()) :: | ||
{:ok, WorkingTree.t()} | {:error, :invalid_repository | :bare} | ||
def get(repository, opts \\ []) when is_pid(repository) and is_list(opts) do | ||
with {:repository_valid?, true} <- {:repository_valid?, Repository.valid?(repository)}, | ||
{:working_tree, working_tree} when is_pid(working_tree) <- | ||
{:working_tree, working_tree_from_repo_or_opts(repository, opts)} do | ||
{:ok, working_tree} | ||
else | ||
{:repository_valid?, false} -> {:error, :invalid_repository} | ||
{:working_tree, nil} -> {:error, :bare} | ||
end | ||
end | ||
|
||
defp working_tree_from_repo_or_opts(repository, _opts) do | ||
# TO DO: Allow working tree to be specified via options. | ||
# https://github.com/elixir-git/xgit/issues/133 | ||
# (NOTE: Should follow through to ensure all relevant plumbing | ||
# modules have that option documented when implemented.) | ||
# For now, only recognize default working tree. | ||
|
||
Repository.default_working_tree(repository) | ||
end | ||
end |