mirror of
https://github.com/daveberrys/guh.git
synced 2026-11-29 00:26:46 +08:00
implement cloning
This commit is contained in:
1 parent
d0cb8499df
commit
e0feb36c78
2 files changed
+46
No files matched your search
@@ -15,6 +15,7 @@ import (
|
|||||||
_ "github.com/daveberrys/guh/src/cmd/stash"
|
_ "github.com/daveberrys/guh/src/cmd/stash"
|
||||||
_ "github.com/daveberrys/guh/src/cmd/undo"
|
_ "github.com/daveberrys/guh/src/cmd/undo"
|
||||||
_ "github.com/daveberrys/guh/src/cmd/cli"
|
_ "github.com/daveberrys/guh/src/cmd/cli"
|
||||||
|
_ "github.com/daveberrys/guh/src/cmd/clone"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() { cmd.Execute() }
|
func main() { cmd.Execute() }
|
||||||
@@ -0,0 +1,45 @@
|
|||||||
|
package clone
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
"os/exec"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"github.com/daveberrys/guh/src/cmd"
|
||||||
|
"github.com/daveberrys/guh/src/utils"
|
||||||
|
"github.com/spf13/cobra"
|
||||||
|
)
|
||||||
|
|
||||||
|
func init() { cmd.RootCmd.AddCommand(cloneCmd) }
|
||||||
|
|
||||||
|
var cloneCmd = &cobra.Command{
|
||||||
|
Use: "clone",
|
||||||
|
Short: "Clone a repository",
|
||||||
|
Args: cobra.MinimumNArgs(1),
|
||||||
|
RunE: func(cobraCmd *cobra.Command, args []string) error {
|
||||||
|
utils.RunGitSequence(false, []string{"clone", args[0]})
|
||||||
|
|
||||||
|
repoName := args[0]
|
||||||
|
if idx := strings.LastIndex(repoName, "/"); idx != -1 {
|
||||||
|
repoName = repoName[idx+1:]
|
||||||
|
}
|
||||||
|
repoName = strings.TrimSuffix(repoName, ".git")
|
||||||
|
|
||||||
|
shell := os.Getenv("SHELL")
|
||||||
|
if shell == "" { shell = "sh" }
|
||||||
|
|
||||||
|
fmt.Println("")
|
||||||
|
fmt.Printf("Spawning in a new shell: %s\n", shell)
|
||||||
|
fmt.Println("This will create a nested shell.")
|
||||||
|
|
||||||
|
sh := exec.Command(shell)
|
||||||
|
sh.Dir = repoName
|
||||||
|
sh.Stdin = os.Stdin
|
||||||
|
sh.Stdout = os.Stdout
|
||||||
|
sh.Stderr = os.Stderr
|
||||||
|
sh.Run()
|
||||||
|
|
||||||
|
return nil
|
||||||
|
},
|
||||||
|
}
|
||||||
Reference in new issue
Block a user