Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions backend/internal/adj/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package adj

import (
"os"
"path/filepath"

"github.com/go-git/go-git/v5"
"github.com/go-git/go-git/v5/plumbing"
Expand All @@ -21,6 +22,27 @@ func updateRepo(AdjBranch string) error {
SingleBranch: true,
Depth: 1,
}

// Try to clone the ADJ to a temp directory to check for accessibility to the repo (also checks internet connection)
tempPath := filepath.Join(os.TempDir(), "temp_adj")

// Remove previous failed cloning attempts
if err = os.RemoveAll(tempPath); err != nil {
return err
}

// Try to import the ADJ to the temp directory
_, err = git.PlainClone(tempPath, false, cloneOptions)
if err != nil {
// If the clone fails, work with the local ADJ
return nil
}

// If the clone is succesful, delete the temp files
if err = os.RemoveAll(RepoPath); err != nil {
return err
}

if _, err = os.Stat(RepoPath); os.IsNotExist(err) {
_, err = git.PlainClone(RepoPath, false, cloneOptions)
if err != nil {
Expand Down
Loading