Commit da754af2 authored by Alain Takoudjou's avatar Alain Takoudjou Committed by Kirill Smelkov

pull: do not fail if folder ends with .git and is not a git repository

If there is a folder in git repositories which ends with .git and which
is not a git repository, git-backup will fail because it will try to use
it as a git repository.

This patch just checks if it's really a git repo before continue inside.

[kirr: Reworked the patch a bit]
/reviewed-on: !8
parent 0985ff32
......@@ -494,6 +494,13 @@ func cmd_pull_(ctx context.Context, gb *git.Repository, pullspecv []PullSpec) {
if !strings.HasSuffix(path, ".git") {
return nil
head, err := os.Stat(path + "/HEAD")
if os.IsNotExist(err) || head.IsDir() {
return nil // not a git repository
if err != nil {
return err
// git repo - let's pull all refs from it to our backup refs namespace
infof("# git %s\t<- %s", prefix, path)
......@@ -1012,7 +1019,7 @@ func cmd_restore_(ctx context.Context, gb *git.Repository, HEAD_ string, restore
// empty - without refs at all, and thus next "git packs restore"
// step will not be run for it.
filedir := pathpkg.Dir(filename)
if strings.HasSuffix(filedir, ".git") && !repos_seen.Contains(filedir) {
if strings.HasSuffix(filename, ".git/HEAD") && !repos_seen.Contains(filedir) {
infof("# repo %s\t-> %s", prefix, filedir)
for _, __ := range []string{"refs/heads", "refs/tags", "objects/pack"} {
err := os.MkdirAll(filedir+"/"+__, 0777)
......@@ -257,8 +257,8 @@ func TestPullRestore(t *testing.T) {
return err
// non *.git/ -- not interesting
if !(info.IsDir() && strings.HasSuffix(path, ".git")) {
// non *.git/ or nongit.git/ -- not interesting
if !(info.IsDir() && strings.HasSuffix(path, ".git")) || info.Name() == "nongit.git" {
return nil
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment