Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use multiple templates in a repo -- Also clone template from specific branch #77

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Allow cloning from a branch in boiler
  • Loading branch information
jasimmk committed Sep 23, 2019
commit 338fd0563dcb083c654f3344a08bfc1b85e949e8
19 changes: 14 additions & 5 deletions pkg/cmd/download.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import (
"fmt"
"os"

"gopkg.in/src-d/go-git.v4/plumbing"

cli "github.com/spf13/cobra"

"github.com/tmrts/boilr/pkg/boilr"
Expand All @@ -27,9 +29,11 @@ var Download = &cli.Command{

MustValidateTemplateDir()

templateURL, templateName, templateSubFolder := args[0], args[1], GetStringFlag(c, "sub-path")

templateURL, templateName := args[0], args[1]
templateSubFolder := GetStringFlag(c, "sub-path")
templateRemoteBranch := GetStringFlag(c, "branch")
targetDir, err := boilr.TemplatePath(templateName)

if err != nil {
exit.Error(fmt.Errorf("download: %s", err))
}
Expand Down Expand Up @@ -64,10 +68,15 @@ var Download = &cli.Command{
}

// TODO(tmrts): allow fetching other branches than 'master'
if err := git.Clone(targetTmpDir, git.CloneOptions{
gitCloneOptions := git.CloneOptions{
URL: host.URL(templateURL),
}); err != nil {
exit.Error(fmt.Errorf("download: %s", err))
}
if templateRemoteBranch != "" {
gitCloneOptions.ReferenceName = plumbing.NewBranchReferenceName(templateRemoteBranch)
}
fmt.Println(gitCloneOptions)
if err := git.Clone(targetTmpDir, gitCloneOptions); err != nil {
exit.Error(fmt.Errorf("download: Cloning repo - %s", err))
}

// Copy content from sub-folder to target folder
Expand Down
1 change: 1 addition & 0 deletions pkg/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ func Run() {

Download.PersistentFlags().BoolP("force", "f", false, "Overwrite existing template with the same name")
Download.PersistentFlags().StringP("log-level", "l", "error", "log-level for output")
Download.PersistentFlags().StringP("branch", "b", "", "Branch, Commit Id, Tag or other reference to checkout")
Download.PersistentFlags().StringP("sub-path", "p", "", "Path inside the git repo where 'template' folder.")
Template.AddCommand(Download)

Expand Down