Skip to content

Commit

Permalink
Merge pull request #54 from renaultfernandes/feat/show-current-tag-na…
Browse files Browse the repository at this point in the history
…me-in-cog-log

feat(cli): show repo and current tag name in "cog log"
  • Loading branch information
oknozor committed Oct 11, 2020
2 parents 1cd3fc1 + 442da5d commit dcd28e8
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 3 deletions.
3 changes: 2 additions & 1 deletion cog.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ authors = [
{ signature = "Paul Delafosse", username = "oknozor" },
{ signature = "Jack Dorland", username = "jackdorland" },
{ signature = "Mike Lubinets", username = "mersinvald" },
{ signature = "Marcin Puc", username = "tranzystorek-io" }
{ signature = "Marcin Puc", username = "tranzystorek-io" },
{ signature = "Renault Fernandes", username = "renaultfernandes" },
]


Expand Down
8 changes: 6 additions & 2 deletions src/bin/cog.rs
Original file line number Diff line number Diff line change
Expand Up @@ -223,10 +223,14 @@ fn main() -> Result<()> {
LOG => {
let cocogitto = CocoGitto::get()?;

let repo_tag_name = match cocogitto.get_repo_tag_name() {
Some(name) => name,
None => "cog log".to_string(),
};

let mut output = Output::builder()
.with_pager_from_env("PAGER")
// TODO: replace with "repo_name:latest_tag"?
.with_file_name("cog log")
.with_file_name(repo_tag_name)
.build()?;

let subcommand = matches.subcommand_matches(LOG).unwrap();
Expand Down
19 changes: 19 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,25 @@ impl CocoGitto {
self.repository.get_author()
}

pub fn get_repo_tag_name(&self) -> Option<String> {
let mut repo_tag_name = String::new();

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_str(&latest_tag);
};

Some(repo_tag_name)
}

pub fn check_and_edit(&self) -> Result<()> {
let from = self.repository.get_first_commit()?;
let head = self.repository.get_head_commit()?;
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 dcd28e8

Please sign in to comment.