Fix parsing of git branch encoded in file name

If the folder has a trailing '/' we picked the wrong substring as branch
name.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
Dirk Hohndel 2015-05-28 08:14:16 -07:00
parent b76a0f0b97
commit e3215123d1

View file

@ -209,6 +209,7 @@ static struct git_repository *is_remote_git_repository(const char *remote, const
struct git_repository *is_git_repository(const char *filename, const char **branchp)
{
int flen, blen, ret;
int offset = 1;
struct stat st;
git_repository *repo;
char *loc, *branch;
@ -223,8 +224,10 @@ struct git_repository *is_git_repository(const char *filename, const char **bran
blen++;
/* Ignore slashes at the end of the repo name */
while (flen && filename[flen-1] == '/')
while (flen && filename[flen-1] == '/') {
flen--;
offset++;
}
if (!flen)
return NULL;
@ -248,7 +251,7 @@ struct git_repository *is_git_repository(const char *filename, const char **bran
if (!loc)
return dummy_git_repository;
branch = format_string("%.*s", blen, filename+flen+1);
branch = format_string("%.*s", blen, filename + flen + offset);
if (!branch) {
free(loc);
return dummy_git_repository;