Skip to content

Commit

Permalink
add support for multiple git config stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
Hermsi1337 committed May 7, 2019
1 parent 7492726 commit 7664b80
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 7 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ protodep
dist/
service/protodep.lock
proto/
dependency/protodep.lock
1 change: 0 additions & 1 deletion cmd/up.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,6 @@ var upCmd = &cobra.Command{

func initDepCmd() {
upCmd.PersistentFlags().BoolP(forceUpdateFlag, "f", false, "update locked file and .proto vendors")
upCmd.PersistentFlags().BoolP(httpsOnlyFlag, "o", false, "use https only for downloading dependencies")
upCmd.PersistentFlags().StringP(httpsUsernameFlag, "u", "", "set username for https authentication")
upCmd.PersistentFlags().StringP(httpsPasswordFlag, "s", "", "set password for https authentication")
upCmd.PersistentFlags().StringP(sshIdentityFileFlag, "i", "id_rsa", "set name identity file for ssh-connection")
Expand Down
29 changes: 23 additions & 6 deletions service/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,16 +60,33 @@ func (s *SyncImpl) Resolve(forceUpdate bool) error {
var authProvider helper.AuthProvider
for _, dep := range protodep.Dependencies {

repoURL, err := url.Parse("https://" + dep.Target)
depRepoURL, err := url.Parse(dep.Target)
if err != nil {
return err
}
bareDepHostname := depRepoURL.Hostname()
bareDepRepoPath := strings.TrimPrefix(depRepoURL.RawPath, "/")
bareDepRepo := bareDepHostname + "/" + bareDepRepoPath

repoURL, err := url.Parse("https://" + bareDepRepo)
if err != nil {
return err
}

repoHostnameWithScheme := repoURL.Scheme + "://" + repoURL.Hostname()
sshGitRepo := helper.GitConfig(repoHostnameWithScheme)
if len(sshGitRepo) > 0 {
dep.Target = sshGitRepo+repoURL.Path
authProvider = s.authProviderSSH
rewritedGitRepo := helper.GitConfig(repoHostnameWithScheme)
if len(rewritedGitRepo) > 0 {
rewritedGitRepoURL, err := url.Parse(rewritedGitRepo)
if err != nil {
return err
}

dep.Target = rewritedGitRepo + repoURL.Path
if rewritedGitRepoURL.Scheme == "ssh" {
authProvider = s.authProviderSSH
} else {
authProvider = s.authProviderHTTPS
}
} else {
authProvider = s.authProviderHTTPS
}
Expand Down Expand Up @@ -116,7 +133,7 @@ func (s *SyncImpl) Resolve(forceUpdate bool) error {
}

newdeps = append(newdeps, dependency.ProtoDepDependency{
Target: repo.Dep.Target,
Target: bareDepRepo,
Branch: repo.Dep.Branch,
Revision: repo.Hash,
Path: repo.Dep.Path,
Expand Down

0 comments on commit 7664b80

Please sign in to comment.