Kiln » gitkiln Read More
Clone URL:  
Pushed to one repository · View In Graph Contained in master

we have namespaces; don't be stupidly redundant

Changeset 192fa27a9dbc

Parent b56064d5e3cc

by Profile picture of User 12Benjamin Pollack <benjamin@fogcreek.com>

Changes to 3 files · Browse files at 192fa27a9dbc Showing diff from parent b56064d5e3cc Diff from another changeset...

Change 1 of 5 Show Entire File kiln/​api.go Stacked
 
8
9
10
11
 
12
13
14
 
16
17
18
19
 
20
21
22
23
24
25
 
26
27
28
29
30
31
32
33
 
 
 
 
 
 
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
54
55
56
 
57
58
59
60
61
62
 
63
64
65
 
72
73
74
75
 
76
77
78
79
80
81
82
 
83
84
85
86
87
88
89
 
90
91
92
93
94
95
96
 
97
98
99
 
114
115
116
117
 
118
119
120
 
122
123
124
125
 
126
127
128
 
8
9
10
 
11
12
13
14
 
16
17
18
 
19
20
21
22
23
24
 
25
26
27
 
 
 
 
 
 
28
29
30
31
32
33
34
35
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
 
56
57
58
59
60
61
 
62
63
64
65
 
72
73
74
 
75
76
77
78
79
80
81
 
82
83
84
85
86
87
88
 
89
90
91
92
93
94
95
 
96
97
98
99
 
114
115
116
 
117
118
119
120
 
122
123
124
 
125
126
127
128
@@ -8,7 +8,7 @@
 )    // Represents the error JSON returned by Kiln API requests -type KilnError struct { +type ApiError struct {   // Guaranteed-unique code for Kiln errors   Code string `json:"codeError"`   // Human-readable description @@ -16,50 +16,50 @@
 }    // Represents the project JSON returned from the Kiln API -type KilnProject struct { +type Project struct {   Id int64 `json:"ixProject"`   Slug string `json:"sSlug"`   Name string `json:"sName"`   Description string `json:"sDescription"`   DefaultPermission string `json:"permissionDefault"` - RepoGroups []KilnRepoGroup + RepoGroups []RepoGroup  }   -type KilnRepoGroup struct { - Id int64 `json:"ixRepoGroup"` - ProjectId int64 `json:"ixProject"` - Slug string `json:"sSlug"` - Name string `json:"sName"` - Repos []KilnRepo `json:"repos"` +type RepoGroup struct { + Id int64 `json:"ixRepoGroup"` + ProjectId int64 `json:"ixProject"` + Slug string `json:"sSlug"` + Name string `json:"sName"` + Repos []Repo `json:"repos"`  }   -type KilnRepo struct { - Id int64 `json:"ixRepo"` - RepoGroupId int64 `json:"ixRepoGroup"` - ParentId int64 `json:"ixParent"` - IsCentral bool `json:"fCentral"` - Slug string `json:"sSlug"` - GroupSlug string `json:"sGroupSlug"` - ProjectSlug string `json:"sProjectSlug"` - GitUrl string `json:"sGitUrl"` - GitSshUrl string `json:"sGitSshUrl"` - Name string `json:"sName"` - Description string `json:"sDescription"` - Status string `json:"sStatus"` - Size int64 `json:"bytesSize"` - Vcs int `json:"vcs"` - Creator KilnPerson `json:"personCreator"` - DefaultPermission string `json:"permissionDefault"` - Branches []KilnRepo `json:"repoBranches"` +type Repo struct { + Id int64 `json:"ixRepo"` + RepoGroupId int64 `json:"ixRepoGroup"` + ParentId int64 `json:"ixParent"` + IsCentral bool `json:"fCentral"` + Slug string `json:"sSlug"` + GroupSlug string `json:"sGroupSlug"` + ProjectSlug string `json:"sProjectSlug"` + GitUrl string `json:"sGitUrl"` + GitSshUrl string `json:"sGitSshUrl"` + Name string `json:"sName"` + Description string `json:"sDescription"` + Status string `json:"sStatus"` + Size int64 `json:"bytesSize"` + Vcs int `json:"vcs"` + Creator Person `json:"personCreator"` + DefaultPermission string `json:"permissionDefault"` + Branches []Repo `json:"repoBranches"`  }   -type KilnPerson struct { +type Person struct {   Id int64 `json:"ixPerson"`   Name string `json:"sName"`   Email string `json:"sEmail"`  }   -func (k *KilnClient) CreateBranch(repoPath, branchName string) (newRepo *KilnRepo, err error) { +func (k *Client) CreateBranch(repoPath, branchName string) (newRepo *Repo, err error) {   r, err := k.RepoForPath(repoPath)   if err != nil {   return @@ -72,28 +72,28 @@
  }   var resp []byte   if resp, err = k.apiPost("Repo/Create", params); err == nil { - var errors map[string][]KilnError + var errors map[string][]ApiError   if err = json.Unmarshal(resp, &errors); err == nil {   if kilnErr, _ := errors["errors"]; len(kilnErr) > 0 {   err = fmt.Errorf("failed: %v\n", kilnErr[0].Description)   return   }   } - newRepo = new(KilnRepo) + newRepo = new(Repo)   err = json.Unmarshal(resp, newRepo)   return   }   return  }   -func (k *KilnClient) Projects() (projects []KilnProject, err error) { +func (k *Client) Projects() (projects []Project, err error) {   if resp, err := k.apiGet("Project", apiParams{}); err == nil {   err = json.Unmarshal(resp, &projects)   }   return  }   -func (k *KilnClient) RepoForPath(repoPath string) (*KilnRepo, error) { +func (k *Client) RepoForPath(repoPath string) (*Repo, error) {   parts := strings.Split(repoPath, "/")   if len(parts) != 3 {   return nil, fmt.Errorf("unknown repository target: %v", repoPath) @@ -114,7 +114,7 @@
  return nil, fmt.Errorf("repository not found")  }   -func (k *KilnClient) IdForRepo(repoPath string) (int64, error) { +func (k *Client) IdForRepo(repoPath string) (int64, error) {   repo, err := k.RepoForPath(repoPath)   if err != nil {   return -1, err @@ -122,7 +122,7 @@
  return repo.Id, nil  }   -func (k *KilnClient) RelatedRepos(repoPath string) (repos []KilnRepo, err error) { +func (k *Client) RelatedRepos(repoPath string) (repos []Repo, err error) {   repoId, err := k.IdForRepo(repoPath)   if err == nil {   resp, err := k.apiGet(fmt.Sprintf("Repo/%v/Related", repoId), apiParams{})
Change 1 of 16 Show Entire File kiln/​kiln.go Stacked
 
18
19
20
21
22
 
 
23
24
25
26
 
27
28
29
 
34
35
36
37
38
39
 
 
 
40
41
42
43
44
45
46
47
 
 
 
 
48
49
50
 
54
55
56
57
 
58
59
60
 
64
65
66
67
 
68
69
70
 
77
78
79
80
81
 
 
82
83
84
85
86
87
 
88
89
90
 
98
99
100
101
 
102
103
104
 
109
110
111
112
 
113
114
115
 
122
123
124
125
 
126
127
128
129
130
 
131
132
133
134
135
 
136
137
138
139
140
 
141
142
143
 
145
146
147
148
 
149
150
151
 
154
155
156
157
 
158
159
160
 
163
164
165
166
 
167
168
169
 
213
214
215
216
 
217
218
219
220
221
 
222
223
224
225
226
 
227
228
229
230
231
 
232
233
234
235
236
 
237
238
239
240
 
241
242
243
 
288
289
290
291
292
 
 
293
294
295
 
300
301
302
303
 
304
305
306
 
314
315
316
317
 
318
319
320
 
324
325
326
327
 
328
329
330
 
331
332
333
 
18
19
20
 
 
21
22
23
24
25
 
26
27
28
29
 
34
35
36
 
 
 
37
38
39
40
41
42
43
 
 
 
 
44
45
46
47
48
49
50
 
54
55
56
 
57
58
59
60
 
64
65
66
 
67
68
69
70
 
77
78
79
 
 
80
81
82
83
84
85
86
 
87
88
89
90
 
98
99
100
 
101
102
103
104
 
109
110
111
 
112
113
114
115
 
122
123
124
 
125
126
127
128
129
 
130
131
132
133
134
 
135
136
137
138
139
 
140
141
142
143
 
145
146
147
 
148
149
150
151
 
154
155
156
 
157
158
159
160
 
163
164
165
 
166
167
168
169
 
213
214
215
 
216
217
218
219
220
 
221
222
223
224
225
 
226
227
228
229
230
 
231
232
233
234
235
 
236
237
238
239
 
240
241
242
243
 
288
289
290
 
 
291
292
293
294
295
 
300
301
302
 
303
304
305
306
 
314
315
316
 
317
318
319
320
 
324
325
326
 
327
328
329
 
330
331
332
333
@@ -18,12 +18,12 @@
 )    // Holds the bare minimum amount of information required to talk to a Kiln instance -type KilnClient struct { - credentials *kilnCredential +type Client struct { + credentials *credential  }    // Stores kiln credentials in the Kiln configuration file -type kilnCredential struct { +type credential struct {   // Base URL of Kiln instance   KilnUrl string `json:"kilnUrl"`   // User for whom this token applies @@ -34,17 +34,17 @@
   type apiParams map[string]string   -type KilnCredentials map[string]map[string]string - -func NewKilnClient(kilnUrl *url.URL) *KilnClient { +type Credentials map[string]map[string]string + +func NewClient(kilnUrl *url.URL) *Client {   user := ""   if kilnUrl.User != nil {   user = kilnUrl.User.Username()   } - return &KilnClient{&kilnCredential{KilnUrl: kilnUrl.String(), User: user}} -} - -func (k *KilnClient) LoadCredentials() bool { + return &Client{&credential{KilnUrl: kilnUrl.String(), User: user}} +} + +func (k *Client) LoadCredentials() bool {   if creds, err := loadCredentials(); err == nil {   if token, ok := creds[k.credentials.User][k.credentials.KilnUrl]; ok {   k.credentials.Token = token @@ -54,7 +54,7 @@
  return false  }   -func (k *KilnClient) StoreCredentials() (err error) { +func (k *Client) StoreCredentials() (err error) {   creds, _ := loadCredentials()   if _, ok := creds[k.credentials.User]; !ok {   creds[k.credentials.User] = make(map[string]string) @@ -64,7 +64,7 @@
  return  }   -func (k *KilnClient) DeleteCredentials() (err error) { +func (k *Client) DeleteCredentials() (err error) {   creds, err := loadCredentials()   if err != nil {   return @@ -77,14 +77,14 @@
 }    // Logs a user into Kiln, returning true and storing their token in the -// KilnClient if successful, and returning an error otherwise -func (k *KilnClient) Logon() error { +// Client if successful, and returning an error otherwise +func (k *Client) Logon() error {   login, password := requestUserCredentials()   resp, err := k.apiGet("Auth/Login", apiParams{"sUser": login, "sPassword": password})   if err != nil {   return fmt.Errorf("unable to contact Kiln: %v\n", err)   } - var errors map[string][]KilnError + var errors map[string][]ApiError   if err = json.Unmarshal(resp, &errors); err == nil {   if err, _ := errors["errors"]; len(err) > 0 {   return fmt.Errorf("failed: %v\n", err[0].Description) @@ -98,7 +98,7 @@
   // Makes sure the client has credentials, taking them through the logon  // sequence if not -func (k *KilnClient) EnsureCredentials() error { +func (k *Client) EnsureCredentials() error {   if k.credentials.Token == "" && !k.LoadCredentials() {   if err := k.Logon(); err != nil {   return err @@ -109,7 +109,7 @@
 }    // Resolve a Git SHA -func (k *KilnClient) ResolveSHA(commit string) (string, error) { +func (k *Client) ResolveSHA(commit string) (string, error) {   if out, err := exec.Command("git", "rev-parse", commit).CombinedOutput(); err == nil {   commit := strings.TrimSpace(string(out))   if strings.HasPrefix(commit, "fatal:") { @@ -122,22 +122,22 @@
 }    // Browses the history tab of the repository -func (k *KilnClient) BrowseHistory(repo string) error { +func (k *Client) BrowseHistory(repo string) error {   return browse(k.repoRoute(repo, ""))  }    // Browse the settings tab for the repository -func (k *KilnClient) BrowseSettings(repo string) error { +func (k *Client) BrowseSettings(repo string) error {   return browse(k.repoRoute(repo, "Settings"))  }    // Browse the related tab for repository -func (k *KilnClient) BrowseRelated(repo string) error { +func (k *Client) BrowseRelated(repo string) error {   return browse(k.repoRoute(repo, "Related"))  }    // Browse a commit, expanding out to the full SHA beforehand -func (k *KilnClient) BrowseCommit(repo string, commit string) (err error) { +func (k *Client) BrowseCommit(repo string, commit string) (err error) {   if commit, err = k.ResolveSHA(commit); err == nil {   err = browse(k.repoRoute(repo, "History/"+commit))   } @@ -145,7 +145,7 @@
 }    // Browse a file in Kiln -func (k *KilnClient) BrowseFile(repo string, file string) error { +func (k *Client) BrowseFile(repo string, file string) error {   path, err := repoRelativePath(file)   if err != nil {   return err @@ -154,7 +154,7 @@
 }    // Browse an annotated file in Kiln -func (k *KilnClient) BrowseAnnotatedFile(repo string, file string) error { +func (k *Client) BrowseAnnotatedFile(repo string, file string) error {   path, err := repoRelativePath(file)   if err != nil {   return err @@ -163,7 +163,7 @@
 }    // Browse a file in Kiln -func (k *KilnClient) BrowseFileHistory(repo string, file string) error { +func (k *Client) BrowseFileHistory(repo string, file string) error {   path, err := repoRelativePath(file)   if err != nil {   return err @@ -213,31 +213,31 @@
 }    // Returns the full URL for relative Kiln URL -func (k *KilnClient) kilnRoute(route string) string { +func (k *Client) kilnRoute(route string) string {   return strings.TrimRight(k.credentials.KilnUrl, "/") + "/" + strings.TrimLeft(route, "/")  }    // Returns the full URL for an API call in Kiln -func (k *KilnClient) apiRoute(route string) string { +func (k *Client) apiRoute(route string) string {   return k.kilnRoute("Api/1.0/" + strings.TrimLeft(route, "/"))  }    // Returns the full URL for a given API call or Kiln route -func (k *KilnClient) repoRoute(repo string, action string) string { +func (k *Client) repoRoute(repo string, action string) string {   return k.kilnRoute(fmt.Sprintf("Code/%v/%v", repo, action))  }    // Returns the body from an API call via HTTP GET -func (k *KilnClient) apiGet(route string, params apiParams) ([]byte, error) { +func (k *Client) apiGet(route string, params apiParams) ([]byte, error) {   return k.apiRequest(route, params, "GET")  }    // Returns the body from an API call via HTTP POST -func (k *KilnClient) apiPost(route string, params apiParams) ([]byte, error) { +func (k *Client) apiPost(route string, params apiParams) ([]byte, error) {   return k.apiRequest(route, params, "POST")  }   -func (k *KilnClient) apiRequest(route string, params apiParams, method string) ([]byte, error) { +func (k *Client) apiRequest(route string, params apiParams, method string) ([]byte, error) {   v := url.Values{}   for key, value := range params {   v.Set(key, value) @@ -288,8 +288,8 @@
 }    // Load any existing credentials from the user's credential store -func loadCredentials() (credentials KilnCredentials, err error) { - credentials = make(KilnCredentials) +func loadCredentials() (credentials Credentials, err error) { + credentials = make(Credentials)   path := filepath.Join(configDirectory(), "kiln_client.json")   fd, err := os.Open(path)   if err != nil { @@ -300,7 +300,7 @@
  if err != nil {   return   } - var creds []kilnCredential + var creds []credential   if err = json.Unmarshal(data, &creds); err != nil {   return   } @@ -314,7 +314,7 @@
 }    // Store all credentials in the credential store, overwriting any already present -func (credentials KilnCredentials) storeCredentials() (err error) { +func (credentials Credentials) storeCredentials() (err error) {   if err = os.MkdirAll(configDirectory(), 0700); err != nil {   return   } @@ -324,10 +324,10 @@
  return   }   defer fd.Close() - creds := make([]*kilnCredential, 0, 10) + creds := make([]*credential, 0, 10)   for user, urls := range credentials {   for url, token := range urls { - creds = append(creds, &kilnCredential{KilnUrl: url, User: user, Token: token}) + creds = append(creds, &credential{KilnUrl: url, User: user, Token: token})   }   }   data, _ := json.Marshal(creds)
Change 1 of 4 Show Changes Only main.go Stacked
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
 
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
 
 
136
137
138
139
140
141
142
143
144
145
146
 
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
 
290
291
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
 
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
 
 
134
135
136
137
138
139
140
141
142
143
144
145
 
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
 
289
290
291
 package main    import (   "fmt"   "net/url"   "os"   "os/exec"   "strings"     "developers.kilnhg.com/Code/Kiln/Group/gitkiln/kiln"  )    const documentation = `  USAGE: git-kiln [<command> [args]]    git-kiln provides quick access to the Kiln repository associated with this  repository. To work, git-kiln must be run from within a Git repository  that either has a Kiln HTTP repository as the upstream remote, or has the  config value "kiln.url" set to an HTTP-accessible Kiln repository. The  latter is helpful if you access Kiln via SSH, or have an alternative  repository as your upstream remote.      Commands:     add-remote [--ssh] <repository> [<remote-alias>]   add the provided repository as a remote; if no local   alias is provided, then the name of the repository will   be used as the remote   annotate <file> [<file2> [...]]   annotate one or more files in Kiln   create-branch <branch-name>   create a branch repository in Kiln, which can be added   to your remotes via "gitkiln add-remote"   filehistory <file> [<file2> [...]]   show the history for one or more files in Kiln   history   go to the history of this repository in Kiln   logout   log out of Kiln, disposing your authentication token   related   show related repositories in Kiln, including the   entire graph of which commits have and have not been   merged into branch repositories   settings   go to the settings tab for this repository in Kiln   show <commit> [<commit2> [...]]   go to the provided commits in Kiln. Commit IDs are expanded   locally, so "git-kiln show HEAD^" and similar commands will   work fine.   showfile <file> [<file2> [...]]   show the contents of one or more files in Kiln   version   show gitkiln's version number    If you provide no command, git-kiln will take you to the repository in  Kiln.  `    const kilnUrlSuffix = "kiln/"    func extractUrlsAndPaths(s string) (base *url.URL, path string, err error) {   base, err = url.Parse(s)   if err != nil || (base.Scheme != "http" && base.Scheme != "https") {   out, err := exec.Command("git", "config", "kiln.url").Output()   if err == nil {   base, err = url.Parse(strings.TrimSpace(string(out)))   }   }   if err != nil || (base.Scheme != "http" && base.Scheme != "https") {   err = fmt.Errorf("must either have an HTTP remote or kiln.url specified in config")   return   }     components := strings.Split(base.Path, "/")   l := len(components)   components[l-1] = strings.TrimSuffix(components[l-1], ".git")   path = strings.Join(components[l-3:l], "/")     if strings.HasSuffix(base.Host, ".kilnhg.com") {   base.Path = ""   } else {   idx := strings.Index(base.Path, kilnUrlSuffix)   if idx < 0 {   err = fmt.Errorf("not sure where Kiln is based on %v\n", base)   return   }   base.Path = base.Path[0 : idx+len(kilnUrlSuffix)]   }   return  }    func isGitAvailable() bool {   if err := exec.Command("git", "version").Run(); err != nil {   return false   } else {   return true   }  }    func showHelp() {   fmt.Println(documentation)  }    func ensureArgs(n int, explanation string) bool {   if len(os.Args) < n {   fmt.Fprintln(os.Stderr, explanation)   showHelp()   return false   } else {   return true   }  }   -func requireAuth(k *kiln.KilnClient) { +func requireAuth(k *kiln.Client) {   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) +func findTargets(related []kiln.Repo, project, group, repo string) []kiln.Repo { + targets := make([]kiln.Repo, 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) { +func dispatch(k *kiln.Client, repoPath string) {   var command string   if len(os.Args) == 1 {   command = "history"   } else {   command = os.Args[1]   }     switch command {   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 "annotate":   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 "create-branch":   if ensureArgs(3, "you must provide a branch name to create") {   requireAuth(k)   r, err := k.CreateBranch(repoPath, os.Args[2])   if err != nil {   fmt.Fprintf(os.Stderr, "could not create branch: %v\n", err)   } else {   fmt.Printf("created: %v\n", r.GitUrl)   }   }   case "filehistory":   if ensureArgs(3, "you must provide at least one file to view") {   for _, file := range os.Args[2:len(os.Args)] {   k.BrowseFileHistory(repoPath, file)   }   }   case "help":   showHelp()   case "history":   k.BrowseHistory(repoPath)   case "logout":   if k.LoadCredentials() {   k.DeleteCredentials()   }   case "related":   k.BrowseRelated(repoPath)   case "settings":   k.BrowseSettings(repoPath)   case "show":   if ensureArgs(3, "you must supply at least one commit SHA to show") {   for _, commit := range os.Args[2:len(os.Args)] {   if err := k.BrowseCommit(repoPath, commit); err != nil {   fmt.Fprintf(os.Stderr, "couldn't load commit: %v\n", err)   }   }   }   case "showfile":   if ensureArgs(3, "you must provide at least one file to view") {   for _, file := range os.Args[2:len(os.Args)] {   k.BrowseFile(repoPath, file)   }   }   case "version":   fmt.Println(version)   default:   showHelp()   }  }    func main() {   if !isGitAvailable() {   fmt.Fprintln(os.Stderr, "git not found")   os.Exit(1)   }   if _, err := kiln.GitRoot(); err != nil {   if len(os.Args) == 2 && os.Args[1] == "help" {   showHelp()   return   } else {   fmt.Fprintln(os.Stderr, "git-kiln must be run from within a Git repository; see \"gitkiln help\"")   os.Exit(1)   }   }     bytesOut, err := exec.Command("git", "ls-remote", "--get-url").Output()   repoUrl := strings.TrimSpace(string(bytesOut))   if err != nil || strings.HasPrefix(repoUrl, "fatal:") {   fmt.Fprintln(os.Stderr, "no remote found; set one with \"git remote add\"")   os.Exit(1)   }   kilnUrl, repoPath, err := extractUrlsAndPaths(repoUrl)   if err != nil {   fmt.Fprintf(os.Stderr, "%v\n", err)   os.Exit(1)   } - k := kiln.NewKilnClient(kilnUrl) + k := kiln.NewClient(kilnUrl)   dispatch(k, repoPath)  }