Skip to content

Commit

Permalink
Graft outline of cmd
Browse files Browse the repository at this point in the history
  • Loading branch information
michaeljs1990 committed Jul 4, 2021
1 parent 0121a76 commit bc503e7
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 0 deletions.
57 changes: 57 additions & 0 deletions cli/graft/graft.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package graft

import (
"fmt"
"os"

"github.com/spf13/cobra"

"github.com/pinkluz/arcanist/cli"
"github.com/pinkluz/arcanist/lib/git"
)

type graftCmd struct {
cmd *cobra.Command

remote string
localBranchName string
}

func (f *graftCmd) run(cmd *cobra.Command, args []string) {
repo, err := git.OpenRepo()
if err != nil {
fmt.Println(err)
os.Exit(1)
}

switch len(args) {
case 1:
err := git.Graft(repo, args[0], f.remote, f.localBranchName)
if err != nil {
fmt.Println(err)
os.Exit(1)
}

fmt.Printf("Grafted '%s' into your local repo", args[0])
fmt.Println()
default:
cmd.Help()
os.Exit(0)
}
}

func init() {
graft := &graftCmd{}
graft.cmd = &cobra.Command{
Use: "graft <branch>",
Short: "Place a branch from a given remote in your local working tree",
Long: `Place a branch in your local working copy from a given upstream so you can work off of it.`,
Args: cobra.MinimumNArgs(1),
Run: graft.run,
}

graft.cmd.Flags().StringVarP(&graft.remote, "remote", "r", "origin", "The remote to use when grafting")
graft.cmd.Flags().StringVarP(&graft.localBranchName, "local-branch-name", "b", "", "The branch name to gaft onto")

cli.GetRoot().AddCommand(graft.cmd)
}
11 changes: 11 additions & 0 deletions lib/git/graft.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package git

import (
gogit "github.com/go-git/go-git/v5"
)

func Graft(repo *gogit.Repository, branch string,
remote string, localBranchName string) error {

return nil
}

0 comments on commit bc503e7

Please sign in to comment.