Fix fail clone local repo which head detatched

Set head detach if can't found branch after download

Signed-off-by: Frank Li <lznuaa@gmail.com>
Add test case for clone head detached repo

Signed-off-by: Frank Li <lznuaa@gmail.com>
Signed-off-by: nulltoken <emeric.fermas@gmail.com>
Merge pull request #1286 from lznuaa/master

Fix clone fail if repo head detached