Skip to content

Commit 650999a

Browse files
committed
Add changes to pkg
1 parent 32d0f99 commit 650999a

1 file changed

Lines changed: 22 additions & 0 deletions

File tree

backend/pkg/adj/git.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package adj
22

33
import (
44
"os"
5+
"path/filepath"
56

67
"github.com/go-git/go-git/v5"
78
"github.com/go-git/go-git/v5/plumbing"
@@ -21,6 +22,27 @@ func updateRepo(AdjBranch string) error {
2122
SingleBranch: true,
2223
Depth: 1,
2324
}
25+
26+
// Try to clone the ADJ to a temp directory to check for accessibility to the repo (also checks internet connection)
27+
tempPath := filepath.Join(os.TempDir(), "temp_adj")
28+
29+
// Remove previous failed cloning attempts
30+
if err = os.RemoveAll(tempPath); err != nil {
31+
return err
32+
}
33+
34+
// Try to import the ADJ to the temp directory
35+
_, err = git.PlainClone(tempPath, false, cloneOptions)
36+
if err != nil {
37+
// If the clone fails, work with the local ADJ
38+
return nil
39+
}
40+
41+
// If the clone is succesful, delete the temp files
42+
if err = os.RemoveAll(RepoPath); err != nil {
43+
return err
44+
}
45+
2446
if _, err = os.Stat(RepoPath); os.IsNotExist(err) {
2547
_, err = git.PlainClone(RepoPath, false, cloneOptions)
2648
if err != nil {

0 commit comments

Comments
 (0)