@@ -27,27 +27,28 @@ import (
2727 "fmt"
2828)
2929
30- func RepoInit (name string , auth_type string , auth_value string ) string {
30+ func RepoInit (name string , auth_type string , auth_value string , url string ) string {
3131 repo_path := filepath .Join (GetConfigDir (), name )
3232
3333 if _ , err := os .Stat (repo_path ); os .IsNotExist (err ) {
3434 os .Mkdir (repo_path , os .ModePerm )
3535 }
3636
3737 f , _ := os .Create (repo_path + "/auth.yaml" )
38- f .Write ([]byte ("type: {{.auth_type}}\n value: {{.auth_value}}\n " ))
38+ f .Write ([]byte ("type: {{.auth_type}}\n value: {{.auth_value}}\n url: {{ .repo_url }} \ n " ))
3939 f .Close ()
4040
4141 config := map [string ]string {
4242 "auth_type" : auth_type ,
4343 "auth_value" : auth_value ,
44+ "repo_url" : url ,
4445 }
4546 ParseTemplate (repo_path + "/auth.yaml" , config )
4647
4748 return repo_path
4849}
4950
50- func ParseRepoAuth (path string ) (string , string ) {
51+ func ParseRepoAuth (path string ) (string , string , string ) {
5152 viper .SetConfigType ("yaml" )
5253 viper .SetConfigName ("auth" )
5354 viper .AddConfigPath (path )
@@ -56,33 +57,35 @@ func ParseRepoAuth(path string) (string, string) {
5657 panic (fmt .Errorf ("Fatal error config file: %s \n " , err ))
5758 }
5859
59- return viper .GetString ("type" ), viper .GetString ("value" )
60+ return viper .GetString ("type" ), viper .GetString ("value" ), viper . GetString ( "url" )
6061}
6162
62- func Clone (path string , url string ) {
63- opts := GetCloneOptions (path , url )
63+ func Clone (path string ) {
64+ opts := GetCloneOptions (path )
6465 _ , err := git .PlainClone (filepath .Join (path , "src" ), false , & opts )
6566
6667 if err != nil {
6768 log .Fatal (err )
6869 }
6970}
7071
71- func GetCloneOptions (path string , url string ) git.CloneOptions {
72- switch rtype , rauth := ParseRepoAuth (path ); rtype {
72+ func GetCloneOptions (path string ) git.CloneOptions {
73+ var rtype , rauth , rurl string
74+
75+ switch rtype , rauth , rurl = ParseRepoAuth (path ); rtype {
7376 case "ssh" :
7477 sshAuth , kr := ssh .NewPublicKeysFromFile ("git" , rauth , "" )
7578 if kr != nil {
7679 log .Fatal (kr )
7780 }
7881 return git.CloneOptions {
79- URL : url ,
82+ URL : rurl ,
8083 Auth : sshAuth ,
8184 Progress : os .Stdout ,
8285 }
8386 case "github" :
8487 return git.CloneOptions {
85- URL : url ,
88+ URL : rurl ,
8689 Auth : & http.BasicAuth {
8790 Username : "standardized" , // yes, this can be anything except an empty string
8891 Password : rauth ,
@@ -91,11 +94,11 @@ func GetCloneOptions(path string, url string) git.CloneOptions {
9194 }
9295 }
9396
94- return git.CloneOptions {URL : url , Progress : os .Stdout }
97+ return git.CloneOptions {URL : rurl , Progress : os .Stdout }
9598}
9699
97100func GetPullOptions (path string ) git.PullOptions {
98- switch rtype , rauth := ParseRepoAuth (path ); rtype {
101+ switch rtype , rauth , _ := ParseRepoAuth (path ); rtype {
99102 case "ssh" :
100103 sshAuth , kr := ssh .NewPublicKeysFromFile ("git" , rauth , "" )
101104 if kr != nil {
0 commit comments