-
Notifications
You must be signed in to change notification settings - Fork 1.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
make RepoConfig and CommandBase use absolute system paths #4693
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,7 @@ | ||
use std::path::PathBuf; | ||
|
||
use anyhow::Result; | ||
use sha2::{Digest, Sha256}; | ||
use tokio::sync::OnceCell; | ||
use turbopath::AbsoluteSystemPathBuf; | ||
use turborepo_api_client::APIClient; | ||
|
||
use crate::{ | ||
|
@@ -22,7 +21,7 @@ pub(crate) mod logout; | |
pub(crate) mod unlink; | ||
|
||
pub struct CommandBase { | ||
pub repo_root: PathBuf, | ||
pub repo_root: AbsoluteSystemPathBuf, | ||
pub ui: UI, | ||
user_config: OnceCell<UserConfig>, | ||
repo_config: OnceCell<RepoConfig>, | ||
|
@@ -32,7 +31,11 @@ pub struct CommandBase { | |
} | ||
|
||
impl CommandBase { | ||
pub fn new(args: Args, repo_root: PathBuf, version: &'static str) -> Result<Self> { | ||
pub fn new( | ||
args: Args, | ||
repo_root: AbsoluteSystemPathBuf, | ||
version: &'static str, | ||
) -> Result<Self> { | ||
Ok(Self { | ||
repo_root, | ||
ui: args.ui(), | ||
|
@@ -162,19 +165,34 @@ impl CommandBase { | |
#[cfg(test)] | ||
mod test { | ||
use test_case::test_case; | ||
use turbopath::AbsoluteSystemPathBuf; | ||
|
||
use crate::get_version; | ||
|
||
#[cfg(not(target_os = "windows"))] | ||
#[test_case("/tmp/turborepo", "6e0cfa616f75a61c"; "basic example")] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looks like windows isn't happy with |
||
#[test_case("", "e3b0c44298fc1c14"; "empty string ok")] | ||
fn test_repo_hash(path: &str, expected_hash: &str) { | ||
use std::path::PathBuf; | ||
use super::CommandBase; | ||
use crate::Args; | ||
|
||
let args = Args::default(); | ||
let repo_root = AbsoluteSystemPathBuf::new(path).unwrap(); | ||
let command_base = CommandBase::new(args, repo_root, get_version()).unwrap(); | ||
|
||
let hash = command_base.repo_hash(); | ||
|
||
assert_eq!(hash, expected_hash); | ||
assert_eq!(hash.len(), 16); | ||
} | ||
|
||
#[cfg(target_os = "windows")] | ||
#[test_case("C:\\\\tmp\\turborepo", "0103736e6883e35f"; "basic example")] | ||
fn test_repo_hash_win(path: &str, expected_hash: &str) { | ||
use super::CommandBase; | ||
use crate::Args; | ||
|
||
let args = Args::default(); | ||
let repo_root = PathBuf::from(path); | ||
let repo_root = AbsoluteSystemPathBuf::new(path).unwrap(); | ||
let command_base = CommandBase::new(args, repo_root, get_version()).unwrap(); | ||
|
||
let hash = command_base.repo_hash(); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the lines above do not give an absolute path it is programmer error.