Skip to content

Commit

Permalink
Fix new - abs path warning
Browse files Browse the repository at this point in the history
  • Loading branch information
maciektr committed Mar 7, 2023
1 parent 933157a commit 0bf3a29
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions scarb/src/ops/new.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
use anyhow::{bail, ensure, Context, Result};
use anyhow::{anyhow, bail, ensure, Context, Result};
use camino::{Utf8Path, Utf8PathBuf};
use indoc::{formatdoc, indoc};
use itertools::Itertools;
use std::fs;

use crate::core::{Config, PackageName};
use crate::internal::fsx;
Expand Down Expand Up @@ -100,11 +101,18 @@ fn mk(
// Create project directory in case we are called from `new` op.
fsx::create_dir_all(&path)?;

init_vcs(&path, version_control)?;
write_vcs_ignore(&path, config, version_control)?;
let canonical_path = if let Ok(canonicalize_path) = fs::canonicalize(&path) {
Utf8PathBuf::from_path_buf(canonicalize_path)
.map_err(|path| anyhow!("path `{}` is not UTF-8 encoded", path.display()))?
} else {
path
};

init_vcs(&canonical_path, version_control)?;
write_vcs_ignore(&canonical_path, config, version_control)?;

// Create the `Scarb.toml` file.
let manifest_path = path.join(MANIFEST_FILE_NAME);
let manifest_path = canonical_path.join(MANIFEST_FILE_NAME);
fsx::write(
&manifest_path,
formatdoc! {r#"
Expand All @@ -121,7 +129,7 @@ fn mk(

// Create hello world source files (with respective parent directories) if source directory
// does not exist.
let source_dir = path.join(DEFAULT_SOURCE_DIR_NAME);
let source_dir = canonical_path.join(DEFAULT_SOURCE_DIR_NAME);
if !source_dir.exists() {
fsx::create_dir_all(&source_dir)?;

Expand Down

0 comments on commit 0bf3a29

Please sign in to comment.