erlgit icon indicating copy to clipboard operation
erlgit copied to clipboard

Fix git:branch bug when there is more than one branch with equal SHA-ID

Open mrjaros opened this issue 11 years ago • 3 comments

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"

mrjaros avatar Jul 08 '14 09:07 mrjaros

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.

mrjaros avatar Jul 09 '14 12:07 mrjaros

-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

flycodepl avatar Jul 09 '14 12:07 flycodepl

Good idea to use oksh with strip. I've missed it.

mrjaros avatar Jul 09 '14 12:07 mrjaros