diff --git a/src/cli/commands/patch.rs b/src/cli/commands/patch.rs index 846b453..6bde635 100644 --- a/src/cli/commands/patch.rs +++ b/src/cli/commands/patch.rs @@ -45,8 +45,6 @@ impl PatchCommand { .write_to(&directory, project.cas_dir(), false) .context("failed to write package contents")?; - // TODO: if MANIFEST_FILE_NAME does not exist, try to convert it - setup_patches_repo(&directory)?; println!( diff --git a/src/cli/commands/patch_commit.rs b/src/cli/commands/patch_commit.rs index 180f59a..2152885 100644 --- a/src/cli/commands/patch_commit.rs +++ b/src/cli/commands/patch_commit.rs @@ -1,10 +1,7 @@ use crate::cli::IsUpToDate; use anyhow::Context; use clap::Args; -use pesde::{ - manifest::Manifest, names::PackageNames, patches::create_patch, source::version_id::VersionId, - Project, MANIFEST_FILE_NAME, -}; +use pesde::{names::PackageNames, patches::create_patch, source::version_id::VersionId, Project}; use std::{path::PathBuf, str::FromStr}; #[derive(Debug, Args)] @@ -22,17 +19,28 @@ impl PatchCommitCommand { anyhow::bail!("outdated lockfile, please run the install command first") }; - let (name, version_id) = { - let patched_manifest = std::fs::read_to_string(self.directory.join(MANIFEST_FILE_NAME)) - .context("failed to read patched manifest")?; - let patched_manifest: Manifest = - toml::from_str(&patched_manifest).context("failed to parse patched manifest")?; - - ( - PackageNames::Pesde(patched_manifest.name), - VersionId::new(patched_manifest.version, patched_manifest.target.kind()), - ) - }; + let (name, version_id) = ( + PackageNames::from_escaped( + self.directory + .parent() + .context("directory has no parent")? + .parent() + .context("directory has no grandparent")? + .file_name() + .context("directory grandparent has no name")? + .to_str() + .context("directory grandparent name is not valid")?, + )?, + VersionId::from_escaped( + self.directory + .parent() + .context("directory has no parent")? + .file_name() + .context("directory parent has no name")? + .to_str() + .context("directory parent name is not valid")?, + )?, + ); graph .get(&name) diff --git a/src/names.rs b/src/names.rs index 7ed675f..5491dd8 100644 --- a/src/names.rs +++ b/src/names.rs @@ -104,6 +104,11 @@ impl PackageNames { PackageNames::Wally(name) => name.escaped(), } } + + /// The reverse of `escaped` + pub fn from_escaped(s: &str) -> Result { + PackageNames::from_str(s.replacen('+', "/", 1).as_str()) + } } impl Display for PackageNames { diff --git a/src/source/version_id.rs b/src/source/version_id.rs index 2cfdf35..3012cf4 100644 --- a/src/source/version_id.rs +++ b/src/source/version_id.rs @@ -29,6 +29,11 @@ impl VersionId { pub fn escaped(&self) -> String { format!("{}+{}", self.0, self.1) } + + /// The reverse of `escaped` + pub fn from_escaped(s: &str) -> Result { + VersionId::from_str(s.replacen('+', " ", 1).as_str()) + } } impl Display for VersionId {