Skip to content

Commit

Permalink
filter out tags from HEAD refs
Browse files Browse the repository at this point in the history
  • Loading branch information
o2sh committed Nov 11, 2020
1 parent 59cb0d5 commit c28404d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 17 deletions.
8 changes: 4 additions & 4 deletions src/onefetch/info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ pub struct Info {
git_version: String,
git_username: String,
project_name: String,
current_commit: CommitInfo,
head_refs: CommitInfo,
version: String,
creation_date: String,
pub dominant_language: Language,
Expand Down Expand Up @@ -69,7 +69,7 @@ impl std::fmt::Display for Info {
f,
"{}{}",
&self.get_formatted_subtitle_label("HEAD"),
&self.current_commit.to_string().color(self.text_colors.info),
&self.head_refs.to_string().color(self.text_colors.info),
)?;
}

Expand Down Expand Up @@ -213,7 +213,7 @@ impl Info {
let repo = Repo::new(&config.repo_path)?;
let workdir = repo.get_work_dir()?;
let (repository_name, repository_url) = repo.get_name_and_url()?;
let current_commit_info = repo.get_current_commit_info();
let head_refs = repo.get_head_refs()?;
let pending = repo.get_pending_changes();
let version = repo.get_version()?;
let git_history = Info::get_git_history(&workdir, config.no_merges);
Expand Down Expand Up @@ -241,7 +241,7 @@ impl Info {
git_version: git_v,
git_username: git_user,
project_name: repository_name,
current_commit: current_commit_info?,
head_refs,
version,
creation_date: creation_date?,
dominant_language,
Expand Down
17 changes: 4 additions & 13 deletions src/onefetch/repo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,8 @@ impl Repo {
}
false
})?;
let mut res = String::new();

if !version_name.is_empty() {
res = format!("{}", version_name);
}

Ok(res)
Ok(version_name)
}

pub fn get_pending_changes(&self) -> Result<String> {
Expand Down Expand Up @@ -131,19 +126,15 @@ impl Repo {
Ok((repository_name, remote_url))
}

pub fn get_current_commit_info(&self) -> Result<CommitInfo> {
pub fn get_head_refs(&self) -> Result<CommitInfo> {
let head = self.repo.head()?;
let head_oid = head.target().ok_or("")?;
let refs = self.repo.references()?;
let refs_info = refs
.filter_map(|reference| match reference {
Ok(reference) => match (reference.target(), reference.shorthand()) {
(Some(oid), Some(shorthand)) if oid == head_oid => {
Some(if reference.is_tag() {
String::from("tags/") + shorthand
} else {
String::from(shorthand)
})
(Some(oid), Some(shorthand)) if oid == head_oid && !reference.is_tag() => {
Some(String::from(shorthand))
}
_ => None,
},
Expand Down

0 comments on commit c28404d

Please sign in to comment.