Skip to content

Commit 66463e9

Browse files
committed
Put branch names in the commit picker
1 parent faab5b7 commit 66463e9

File tree

1 file changed

+23
-2
lines changed

1 file changed

+23
-2
lines changed

src/main.rs

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15+
use std::collections::HashMap;
1516
use std::env;
1617
use std::error::Error;
1718
use std::process::Command;
@@ -211,12 +212,32 @@ fn select_commit_to_amend<'a>(
211212
.map(|rev| repo.find_commit(rev))
212213
.collect::<Result<Vec<_>, _>>()?
213214
};
215+
let branches: HashMap<Oid, String> = repo
216+
.branches(None)?
217+
.filter_map(|b| {
218+
b.ok().and_then(|(b, _type)| {
219+
let name: Option<String> = b.name().ok().and_then(|n| n.map(|n| n.to_owned()));
220+
let oid = b.into_reference().resolve().ok().and_then(|r| r.target());
221+
name.and_then(|name| oid.map(|oid| (oid, name)))
222+
})
223+
})
224+
.collect();
214225
let rev_aliases = commits
215226
.iter()
216-
.map(|commit| {
227+
.enumerate()
228+
.map(|(i, commit)| {
229+
let bname = if i > 0 {
230+
branches
231+
.get(&commit.id())
232+
.map(|n| format!("({}) ", n))
233+
.unwrap_or_else(String::new)
234+
} else {
235+
String::new()
236+
};
217237
format!(
218-
"{} {}",
238+
"{} {}{}",
219239
&style(&commit.id().to_string()[0..10]).blue(),
240+
style(bname).green(),
220241
commit.summary().unwrap_or("no commit summary")
221242
)
222243
})

0 commit comments

Comments
 (0)