Changeset b750101b8e1a…
Parent c69c2ff00cbf…
committed by Benjamin Pollack <benjamin@fogcreek.com>
authored by Benjamin Pollack <benjamin@fogcreek.com>
Changes to one file · Browse files at b750101b8e1a Showing diff from parent c69c2ff00cbf Diff from another changeset...
|
@@ -103,6 +103,37 @@ }
}
+func requireAuth(k *kiln.KilnClient) {
+ if err := k.EnsureCredentials(); err != nil {
+ fmt.Fprintf(os.Stderr, "unable to logon: %v\n", err)
+ os.Exit(1)
+ }
+}
+
+func splitRepoPath(repoPath string) (project, group, repo string) {
+ parts := strings.Split(repoPath, "/")
+ repo = parts[len(parts)-1]
+ if len(parts) > 1 {
+ group = parts[len(parts)-2]
+ }
+ if len(parts) > 2 {
+ project = parts[len(parts)-3]
+ }
+ return
+}
+
+func findTargets(related []kiln.KilnRepo, project, group, repo string) []kiln.KilnRepo {
+ targets := make([]kiln.KilnRepo, 0)
+ for _, r := range related {
+ if r.Slug == repo &&
+ (len(group) == 0 || r.GroupSlug == group) &&
+ (len(project) == 0 || r.ProjectSlug == project) {
+ targets = append(targets, r)
+ }
+ }
+ return targets
+}
+
func dispatch(k *kiln.KilnClient, repoPath string) {
var command string
if len(os.Args) == 1 {
@@ -116,6 +147,59 @@ if ensureArgs(3, "you must provide at least one file to annotate") {
for _, file := range os.Args[2:len(os.Args)] {
k.BrowseAnnotatedFile(repoPath, file)
+ }
+ }
+ case "add-remote":
+ if len(os.Args) < 3 || len(os.Args) > 5 {
+ fmt.Fprintf(os.Stderr, "you must provide a repo to add as the remote")
+ showHelp()
+ return
+ }
+
+ requireAuth(k)
+
+ args := os.Args[2:len(os.Args)]
+ ssh := false
+ if args[0] == "--ssh" {
+ ssh = true
+ args = args[1:len(args)]
+ }
+
+ related, err := k.RelatedRepos(repoPath)
+ if err != nil {
+ fmt.Fprintf(os.Stderr, "unable to query related repos: %v\n", err)
+ return
+ }
+
+ project, group, repo := splitRepoPath(args[0])
+ targets := findTargets(related, project, group, repo)
+
+ if len(targets) == 0 {
+ fmt.Fprintf(os.Stderr, "nothing found; you must use exact matches\n")
+ } else if len(targets) > 1 {
+ fmt.Fprintf(os.Stderr, "too many matches; please provide more components\n")
+ fmt.Fprintf(os.Stderr, "Matches:\n")
+ for _, r := range targets {
+ fmt.Fprintf(os.Stderr, "\t%v/%v/%v\n", r.ProjectSlug, r.GroupSlug, r.Slug)
+ }
+ fmt.Fprintln(os.Stderr, "")
+ } else {
+ var remoteName string
+ if len(args) == 2 {
+ remoteName = args[1]
+ } else {
+ remoteName = repo
+ }
+
+ var remoteURL string
+ if ssh {
+ remoteURL = targets[0].GitSshUrl
+ } else {
+ remoteURL = targets[0].GitUrl
+ }
+ out, err := exec.Command("git", "remote", "add", remoteName, remoteURL).CombinedOutput()
+ if err != nil || strings.HasPrefix(string(out), "fatal: ") {
+ fmt.Fprintf(os.Stderr, "could not add remote: %s", out)
}
}
case "filehistory":
|
Loading...