Skip to content

Commit

Permalink
feat(cli): include current branch name in "cog log"
Browse files Browse the repository at this point in the history
  • Loading branch information
renaultfernandes committed Oct 10, 2020
1 parent 061004e commit 2bcf972
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,8 +179,13 @@ impl CocoGitto {
let repo_path = self.repository.get_repo_dir()?.iter().last()?;
repo_tag_name.push_str(repo_path.to_str()?);

if let Some(branch_shorthand) = self.repository.get_branch_shorthand() {
repo_tag_name.push_str(" on ");
repo_tag_name.push_str(&branch_shorthand);
}

if let Ok(latest_tag) = self.repository.get_latest_tag() {
repo_tag_name.push(':');
repo_tag_name.push(' ');
repo_tag_name.push_str(&latest_tag);
};

Expand Down
8 changes: 8 additions & 0 deletions src/repository.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,14 @@ impl Repository {
}
}

pub(crate) fn get_branch_shorthand(&self) -> Option<String> {
if let Ok(head) = self.0.head() {
Some(head.shorthand()?.to_string())
} else {
None
}
}

pub(crate) fn create_tag(&self, name: &str) -> Result<()> {
if self.get_diff(true).is_some() {
return Err(anyhow!(
Expand Down

0 comments on commit 2bcf972

Please sign in to comment.