Skip to content

Commit

Permalink
fix for check command not checking short ids or detatched heads
Browse files Browse the repository at this point in the history
  • Loading branch information
ninjamuffin99 committed Dec 6, 2024
1 parent a934d60 commit 4d71fdf
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 24 deletions.
27 changes: 12 additions & 15 deletions src/commands/check_command.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
use std::process::id;
use std::str::FromStr;
use std::{fs::File, path::Path};

use crate::hmm::haxelib::{Haxelib, HaxelibType};
use crate::hmm::{self, dependencies::Dependancies};
use anyhow::{anyhow, Context, Result};
use bstr::BStr;
use console::Emoji;
use gix::{Object, ObjectId};
use gix::hash::Prefix;
use std::io::Read;
use yansi::Paint;

Expand Down Expand Up @@ -111,22 +108,22 @@ pub fn compare_haxelib_to_hmm(deps: &Dependancies) -> Result<Vec<HaxelibStatus>>
}
};

let head_ref = repo.head_ref()?.unwrap();
// TODO: Need to make sure this unwraps for detatched head!
let head_ref = repo.head_commit().unwrap();

// If our head ref is a tag or branch, we check if we already have it in our history
// If it's not a tag, we check via commit id
let intended_commit = match repo.find_reference(haxelib.vcs_ref.as_ref().unwrap()) {
Ok(r) => r.id(),
Err(_) => {
let commit = repo.find_commit(
ObjectId::from_str(haxelib.vcs_ref.as_ref().unwrap())
.expect("Commit Tag improperly setup?"),
);
commit.unwrap().id()
}
Ok(r) => r.id().shorten_or_id(),
Err(_) => Prefix::from_hex(haxelib.vcs_ref.as_ref().unwrap())?,
};

if head_ref.id() != intended_commit {
if head_ref
.id()
.shorten_or_id()
.cmp_oid(intended_commit.as_oid())
.is_ne()
{
println!(
"{} {}",
haxelib.name.red().bold(),
Expand All @@ -136,7 +133,7 @@ pub fn compare_haxelib_to_hmm(deps: &Dependancies) -> Result<Vec<HaxelibStatus>>
println!(
"Expected: {} | Installed: {} at {}",
haxelib.vcs_ref.as_ref().unwrap().red(),
head_ref.name().shorten().red(),
head_ref.shorten().red(),
head_ref.id().red()
);

Expand Down
9 changes: 0 additions & 9 deletions src/commands/install_command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,20 @@ use crate::hmm::haxelib::Haxelib;
use crate::hmm::haxelib::HaxelibType;
use anyhow::Ok;
use anyhow::{anyhow, Context, Result};
use bstr::BStr;
use bstr::BString;
use console::Emoji;
use futures_util::StreamExt;
use gix::clone;
use gix::create;
use gix::discover::repository;
use gix::open;
use gix::progress;
use gix::progress::Discard;
use gix::submodule;
use gix::Id;
use gix::ObjectId;
use gix::Url;
use human_bytes::human_bytes;
use indicatif::{ProgressBar, ProgressStyle};
use std::env;
use std::fs::File;
use std::io::Write;
use std::num::NonZero;
use std::path::Path;
use std::path::PathBuf;
use std::str::FromStr;
use std::sync::atomic::AtomicBool;
use yansi::Paint;
use zip::ZipArchive;
Expand Down

0 comments on commit 4d71fdf

Please sign in to comment.