Skip to content

Commit

Permalink
fix(volo-build/volo-cli): git should use relative path instead of abs…
Browse files Browse the repository at this point in the history
…olute path (#297)
  • Loading branch information
PureWhiteWu authored Dec 25, 2023
1 parent b34f9cf commit 7b6bab2
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 12 deletions.
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion volo-build/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "volo-build"
version = "0.9.0"
version = "0.9.1"
edition.workspace = true
homepage.workspace = true
repository.workspace = true
Expand Down
12 changes: 11 additions & 1 deletion volo-build/src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,8 @@ pub fn get_or_download_idl(idl: Idl, target_dir: impl AsRef<Path>) -> anyhow::Re
download_files_from_git(task).with_context(|| format!("download repo {repo}"))?;

(
dir.join(&idl.path),
// git should use relative path instead of absolute path
dir.join(strip_slash_prefix(idl.path.as_path())),
idl.includes
.unwrap_or_default()
.into_iter()
Expand Down Expand Up @@ -298,6 +299,15 @@ pub fn git_repo_init(path: &Path) -> anyhow::Result<()> {
Ok(())
}

pub fn strip_slash_prefix(p: &Path) -> PathBuf {
if p.starts_with("/") {
// remove the "/" prefix to the start of idl path
p.strip_prefix("/").unwrap().to_path_buf()
} else {
p.to_path_buf()
}
}

#[cfg(test)]
mod tests {
use std::fs;
Expand Down
2 changes: 1 addition & 1 deletion volo-cli/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "volo-cli"
version = "0.9.0"
version = "0.9.1"
edition.workspace = true
homepage.workspace = true
repository.workspace = true
Expand Down
4 changes: 2 additions & 2 deletions volo-cli/src/idl/add.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::path::PathBuf;
use clap::{value_parser, Parser};
use volo_build::{
model::{Entry, GitSource, Idl, Source},
util::get_repo_latest_commit_id,
util::{get_repo_latest_commit_id, strip_slash_prefix},
};

use crate::{command::CliCommand, context::Context};
Expand Down Expand Up @@ -69,7 +69,7 @@ impl CliCommand for Add {
lock: Some(lock),
}),
touch: vec![],
path: self.idl.clone(),
path: strip_slash_prefix(self.idl.as_path()),
includes: self.includes.clone(),
keep_unknown_fields: false,
}
Expand Down
8 changes: 6 additions & 2 deletions volo-cli/src/idl/update.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
use std::collections::HashSet;

use clap::Parser;
use volo_build::model::{GitSource, Source};
use volo_build::{
model::{GitSource, Source},
util::strip_slash_prefix,
};

use crate::{command::CliCommand, context::Context};

Expand All @@ -22,7 +25,8 @@ impl CliCommand for Update {
let entry = config.entries.get_mut(&cx.entry_name).unwrap();
let mut exists = HashSet::new();

entry.idls.iter().for_each(|idl| {
entry.idls.iter_mut().for_each(|idl| {
idl.path = strip_slash_prefix(idl.path.as_path());
if let Source::Git(ref git) = idl.source {
exists.insert(git.repo.clone());
}
Expand Down
11 changes: 8 additions & 3 deletions volo-cli/src/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use clap::{value_parser, Parser};
use volo_build::{
config_builder::InitBuilder,
model::{Entry, GitSource, Idl, Source, DEFAULT_FILENAME},
util::{get_repo_latest_commit_id, git_repo_init, DEFAULT_CONFIG_FILE},
util::{get_repo_latest_commit_id, git_repo_init, strip_slash_prefix, DEFAULT_CONFIG_FILE},
};

use crate::command::CliCommand;
Expand Down Expand Up @@ -197,8 +197,13 @@ impl CliCommand for Init {
lock,
});
}
idl.path = self.idl.clone();
idl.ensure_readable()?;
if self.git.is_some() {
idl.path = strip_slash_prefix(&self.idl);
} else {
idl.path = self.idl.clone();
// only ensure readable when idl is from local
idl.ensure_readable()?;
}

let mut entry = Entry {
protocol: idl.protocol(),
Expand Down

0 comments on commit 7b6bab2

Please sign in to comment.