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

extract out the resolve-a-SHA functionality

Changeset 543065b40c93

Parent 87c6e5aade72

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

Changes to one file · Browse files at 543065b40c93 Showing diff from parent 87c6e5aade72 Diff from another changeset...

Change 1 of 2 Show Entire File kiln/​kiln.go Stacked
 
108
109
110
 
 
 
 
 
 
 
 
 
 
 
 
 
111
112
113
 
125
126
127
128
129
130
131
132
133
134
135
136
137
 
 
138
139
140
 
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
 
138
139
140
 
 
 
 
 
 
 
 
 
 
141
142
143
144
145
@@ -108,6 +108,19 @@
  return nil  }   +// Resolve a Git SHA +func (k *KilnClient) 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:") { + return "", fmt.Errorf("commit couldn't be resolved (try \"git fetch\" first)") + } else { + return commit, nil + } + } + return "", fmt.Errorf("commit couldn't be resolved (try \"git fetch\" first)") +} +  // Browses the history tab of the repository  func (k *KilnClient) BrowseHistory(repo string) error {   return browse(k.repoRoute(repo, "")) @@ -125,16 +138,8 @@
   // Browse a commit, expanding out to the full SHA beforehand  func (k *KilnClient) BrowseCommit(repo string, commit string) (err error) { - var out []byte - if out, err = exec.Command("git", "rev-parse", commit).CombinedOutput(); err == nil { - commit = strings.TrimSpace(string(out)) - if strings.HasPrefix(commit, "fatal:") { - err = fmt.Errorf("commit couldn't be resolved (try \"git fetch\" first)") - } else { - browse(k.repoRoute(repo, "History/"+commit)) - } - } else { - err = fmt.Errorf("commit couldn't be resolved (try \"git fetch\" first)") + if commit, err = k.ResolveSHA(commit); err == nil { + err = browse(k.repoRoute(repo, "History/"+commit))   }   return  }