@@ -26,13 +26,11 @@ func CloneOrPullRepository(language string) error {
26
26
}
27
27
if exists {
28
28
log .Debugf ("directory %s exists.\n " , repositoryPath )
29
- pullExistingRepository (repositoryPath )
30
- return nil
29
+ return pullExistingRepository (repositoryPath )
31
30
}
32
31
log .Debugf ("directory %s does not exist.\n " , repositoryPath )
33
32
log .Infof ("cloning repository %s into %s\n " , repoURL , repositoryPath )
34
- cloneNewRepository (repoURL , repositoryPath )
35
- return nil
33
+ return cloneNewRepository (repoURL , repositoryPath )
36
34
}
37
35
38
36
func getRepositoryURLByLanguage (language string ) (string , string , error ) {
@@ -41,50 +39,38 @@ func getRepositoryURLByLanguage(language string) (string, string, error) {
41
39
return "" , "" , err
42
40
}
43
41
repositoryPath := userHomeDir + "/.compage/templates/compage-template-" + language
44
- if language == "go" {
45
- return "https://github.com/intelops/compage-template-go.git" , repositoryPath , nil
46
- } else if language == "python" {
47
- return "https://github.com/intelops/compage-template-python.git" , repositoryPath , nil
48
- } else if language == "java" {
49
- return "https://github.com/intelops/compage-template-java.git" , repositoryPath , nil
50
- } else if language == "javascript" {
51
- return "https://github.com/intelops/compage-template-javascript.git" , repositoryPath , nil
52
- } else if language == "ruby" {
53
- return "https://github.com/intelops/compage-template-ruby.git" , repositoryPath , nil
54
- } else if language == "rust" {
55
- return "https://github.com/intelops/compage-template-rust.git" , repositoryPath , nil
56
- } else if language == "typescript" {
57
- return "https://github.com/intelops/compage-template-typescript.git" , repositoryPath , nil
58
- } else if language == "common" {
42
+ repositoryURL := "https://github.com/intelops/compage-template-" + language + ".git"
43
+ if language == "common" {
59
44
repositoryPath = userHomeDir + "/.compage/templates/common-templates"
60
45
return "https://github.com/intelops/common-templates.git" , repositoryPath , nil
61
46
}
62
- return "" , "" , nil
47
+ return repositoryURL , repositoryPath , nil
63
48
}
64
49
65
- func cloneNewRepository (repoURL string , cloneDir string ) {
50
+ func cloneNewRepository (repoURL string , cloneDir string ) error {
66
51
_ , err := git .PlainClone (cloneDir , false , & git.CloneOptions {
67
52
URL : repoURL ,
68
53
Progress : os .Stdout ,
69
54
})
70
55
if err != nil {
71
56
log .Errorf ("error:%v" , err )
72
- return
57
+ return err
73
58
}
74
59
log .Infof ("repository[%s] cloned successfully." , repoURL )
60
+ return nil
75
61
}
76
62
77
- func pullExistingRepository (existingRepositoryPath string ) {
63
+ func pullExistingRepository (existingRepositoryPath string ) error {
78
64
r , err := git .PlainOpen (existingRepositoryPath )
79
65
if err != nil {
80
66
log .Errorf ("error:%v" , err )
81
- return
67
+ return err
82
68
}
83
69
// Get the working directory for the repository
84
70
w , err := r .Worktree ()
85
71
if err != nil {
86
72
log .Errorf ("error:%v" , err )
87
- return
73
+ return err
88
74
}
89
75
// Pull the latest changes from the origin remote and merge into the current branch
90
76
log .Info ("git pull origin" )
@@ -93,21 +79,22 @@ func pullExistingRepository(existingRepositoryPath string) {
93
79
if errors .Is (err , git .NoErrAlreadyUpToDate ) {
94
80
// This is a special error that means we don't have any new changes
95
81
log .Info (err )
96
- return
82
+ return nil
97
83
}
98
84
log .Errorf ("error:%v" , err )
99
- return
85
+ return err
100
86
}
101
87
// Print the latest commit that was just pulled
102
88
ref , err := r .Head ()
103
89
if err != nil {
104
90
log .Errorf ("error:%v" , err )
105
- return
91
+ return err
106
92
}
107
93
commit , err := r .CommitObject (ref .Hash ())
108
94
if err != nil {
109
95
log .Errorf ("error:%v" , err )
110
- return
96
+ return err
111
97
}
112
98
log .Info (commit )
99
+ return nil
113
100
}
0 commit comments