Skip to content

Commit f584b27

Browse files
committed
Fix new - abs path warning
1 parent fe0b0cf commit f584b27

File tree

2 files changed

+40
-4
lines changed

2 files changed

+40
-4
lines changed

scarb/src/ops/new.rs

+11-4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use crate::internal::fsx::PathBufUtf8Ext;
12
use anyhow::{bail, ensure, Context, Result};
23
use camino::{Utf8Path, Utf8PathBuf};
34
use indoc::{formatdoc, indoc};
@@ -100,11 +101,17 @@ fn mk(
100101
// Create project directory in case we are called from `new` op.
101102
fsx::create_dir_all(&path)?;
102103

103-
init_vcs(&path, version_control)?;
104-
write_vcs_ignore(&path, config, version_control)?;
104+
let canonical_path = if let Ok(canonicalize_path) = fsx::canonicalize(&path) {
105+
canonicalize_path.try_into_utf8()?
106+
} else {
107+
path
108+
};
109+
110+
init_vcs(&canonical_path, version_control)?;
111+
write_vcs_ignore(&canonical_path, config, version_control)?;
105112

106113
// Create the `Scarb.toml` file.
107-
let manifest_path = path.join(MANIFEST_FILE_NAME);
114+
let manifest_path = canonical_path.join(MANIFEST_FILE_NAME);
108115
fsx::write(
109116
&manifest_path,
110117
formatdoc! {r#"
@@ -121,7 +128,7 @@ fn mk(
121128

122129
// Create hello world source files (with respective parent directories) if source directory
123130
// does not exist.
124-
let source_dir = path.join(DEFAULT_SOURCE_DIR_NAME);
131+
let source_dir = canonical_path.join(DEFAULT_SOURCE_DIR_NAME);
125132
if !source_dir.exists() {
126133
fsx::create_dir_all(&source_dir)?;
127134

scarb/tests/e2e/new_and_init.rs

+29
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use std::fs;
33
use assert_fs::prelude::*;
44
use indoc::indoc;
55
use predicates::prelude::*;
6+
use toml::{Table, Value};
67

78
use scarb::core::TomlManifest;
89

@@ -146,6 +147,34 @@ fn new_existing() {
146147
"#});
147148
}
148149

150+
#[test]
151+
fn issue_148() {
152+
let pt = assert_fs::TempDir::new().unwrap();
153+
154+
let output = Scarb::quick_snapbox()
155+
.arg("--json")
156+
.arg("new")
157+
.arg("hello")
158+
.current_dir(&pt)
159+
.output()
160+
.expect("Failed to spawn command");
161+
162+
if !output.stdout.is_empty() {
163+
let parsed: Table = serde_json::de::from_slice(&output.stdout).unwrap();
164+
165+
for (_, value) in parsed {
166+
if let Value::String(s) = value {
167+
assert!(!s.contains(
168+
"compiling this new package may not work due to invalid workspace configuration"
169+
));
170+
}
171+
}
172+
}
173+
174+
let t = pt.child("hello");
175+
assert!(t.is_dir());
176+
}
177+
149178
#[test]
150179
fn invalid_package_name() {
151180
let pt = assert_fs::TempDir::new().unwrap();

0 commit comments

Comments
 (0)