diff --git a/internal/git/git.go b/internal/git/git.go deleted file mode 100644 index c41240e..0000000 --- a/internal/git/git.go +++ /dev/null @@ -1,62 +0,0 @@ -// Copyright 2023 Vic Shóstak and Create Go App Contributors. All rights reserved. -// Use of this source code is governed by Apache 2.0 license -// that can be found in the LICENSE file. - -package git - -import ( - "errors" - "fmt" - "net/url" - "os" - "path/filepath" - "strings" - - "github.com/go-git/go-git/v5" - - "github.com/create-go-app/cli/v5/internal/helpers" -) - -// Clone function for `git clone` defined project template. -func Clone(templateType, templateURL string) error { - // Checking for nil. - if templateType == "" || templateURL == "" { - return errors.New("project template not found") - } - - // Get current directory. - currentDir, _ := os.Getwd() - - // Set project folder. - folder := filepath.Join(currentDir, templateType) - - // Clone project template. - _, errPlainClone := git.PlainClone( - folder, - false, - &git.CloneOptions{ - URL: getAbsoluteURL(templateURL), - }, - ) - if errPlainClone != nil { - return fmt.Errorf("repository '%v' was not cloned", templateURL) - - } - - // Cleanup project. - helpers.RemoveFolders([]string{".git", ".github"}) - - return nil -} - -// getAbsolutURL func for help define correct HTTP protocol. -func getAbsoluteURL(templateURL string) string { - templateURL = strings.TrimSpace(templateURL) - u, _ := url.Parse(templateURL) - - if u.Scheme == "" { - u.Scheme = "https" - } - - return u.String() -} diff --git a/internal/git/git_test.go b/internal/git/git_test.go deleted file mode 100644 index 5e16cc7..0000000 --- a/internal/git/git_test.go +++ /dev/null @@ -1,102 +0,0 @@ -package git - -import ( - "os" - "testing" -) - -func TestGitClone(t *testing.T) { - type args struct { - rootFolder string - templateName string - } - tests := []struct { - name string - args args - wantErr bool - }{ - { - "successfully cloned project", - args{ - rootFolder: "../../tmp/test", - templateName: "github.com/koddr/koddr", - }, - false, - }, - { - "failed clone project (empty template)", - args{ - rootFolder: "../../tmp/test", - templateName: "", - }, - true, - }, - { - "failed clone project", - args{ - rootFolder: "../../tmp/test", - templateName: "404.404/404/404", - }, - true, - }, - { - "failed clone project (empty args)", - args{}, - true, - }, - } - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - if err := Clone(tt.args.rootFolder, tt.args.templateName); (err != nil) != tt.wantErr { - t.Errorf("Clone() error = %v, wantErr %v", err, tt.wantErr) - } - }) - - // Clean - err := os.RemoveAll("../../tmp") - if err != nil { - return - } - } -} - -func Test_getAbsoluteURL(t *testing.T) { - type args struct { - templateURL string - } - tests := []struct { - name string - args args - want string - }{ - { - "successfully get absolute url from url with scheme", - args{ - templateURL: "https://github.com/create-go-app/net_http-go-template", - }, - "https://github.com/create-go-app/net_http-go-template", - }, - { - "successfully get absolute url from url without scheme", - args{ - templateURL: "github.com/create-go-app/net_http-go-template", - }, - "https://github.com/create-go-app/net_http-go-template", - }, - { - "successfully get absolute url from url starting space", - args{ - templateURL: " github.com/create-go-app/net_http-go-template", - }, - "https://github.com/create-go-app/net_http-go-template", - }, - } - - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - if got := getAbsoluteURL(tt.args.templateURL); got != tt.want { - t.Errorf("getAbsoluteURL() = %v, want %v", got, tt.want) - } - }) - } -}