erlgit
erlgit copied to clipboard
Fix git:branch bug when there is more than one branch with equal SHA-ID
This fixes badmatch error when we have more than one branch with equal sha-id. In such case, you tried to match one-element list ([B]) with list of branches (["branchA", "branchB"]). Now we just return list of branches, separated with "; ", ex. "branchA; branchB"
hmm, how about just
branch(Repo) ->
case status_is_detached(Repo) of
false ->
{ok, B} = sh("git rev-parse --abbrev-ref HEAD", [{cd, Repo}]),
B--"\n";
true ->
detached
end.
-spec branch(dir()) -> {'ok', branch()} | 'detached'.
branch(Repo) ->
case status_is_detached(Repo) of
false ->
CurrentBranch = strip(oksh("git symbolic-ref --short HEAD", [{cd, Repo}])),
{ok, CurrentBranch};
true ->
detached
end.
And if you don't want to use
git symbolic-ref --short HEAD
see other options: http://stackoverflow.com/a/19585361
Good idea to use oksh with strip. I've missed it.