History

fix!: Remove `git-config` test utilities from `git-path`.

Sebastian Thiel committed 4 years ago

Commit c9933c01 parent aaf1cde4 files · +48 −53Browse files

Showing the changes to git-path/src (1 of 4 files). Show all

Unified · Split

git-path/src/lib.rs+3−49
@@ -1,4 +1,4 @@
1#![forbid(unsafe_code, rust_2018_idioms)]1#![forbid(unsafe_code, rust_2018_idioms, missing_docs)]
2//! This crate contains an assortment of utilities to deal with paths and their conversions.2//! This crate contains an assortment of utilities to deal with paths and their conversions.
3//!3//!
4//! Generally `git` treats paths as bytes, but inherently assumes non-illformed UTF-8 as encoding on windows. Internally, it expects4//! Generally `git` treats paths as bytes, but inherently assumes non-illformed UTF-8 as encoding on windows. Internally, it expects
@@ -55,56 +55,10 @@ · 50 unmodified lines
55pub struct Spec(bstr::BString);55pub struct Spec(bstr::BString);
56 56
57mod convert;57mod convert;
58mod spec;
59
60use std::{fs::create_dir_all, ops::Deref, path::Path};
61
62pub use convert::*;58pub use convert::*;
63use tempfile::tempdir_in;59
60mod spec;
64 61
65///62///
66pub mod realpath;63pub mod realpath;
67pub use realpath::function::{realpath, realpath_opts};64pub use realpath::function::{realpath, realpath_opts};
68
69pub fn create_symlink(from: &Path, to: &Path) {
70 create_dir_all(from.parent().unwrap()).unwrap();
71 #[cfg(not(target_os = "windows"))]
72 std::os::unix::fs::symlink(to, &from).unwrap();
73 #[cfg(target_os = "windows")]
74 std::os::windows::fs::symlink_file(to, &from).unwrap();
75}
76
77pub struct CanonicalizedTempDir {
78 pub dir: tempfile::TempDir,
79}
80
81impl CanonicalizedTempDir {
82 pub fn new() -> Self {
83 #[cfg(windows)]
84 let canonicalized_tempdir = std::env::temp_dir();
85 #[cfg(not(windows))]
86 let canonicalized_tempdir = std::env::temp_dir().canonicalize().unwrap();
87 let dir = tempdir_in(canonicalized_tempdir).unwrap();
88 Self { dir }
89 }
90}
91
92impl Default for CanonicalizedTempDir {
93 fn default() -> Self {
94 Self::new()
95 }
96}
97
98impl AsRef<Path> for CanonicalizedTempDir {
99 fn as_ref(&self) -> &Path {
100 self
101 }
102}
103
104impl Deref for CanonicalizedTempDir {
105 type Target = Path;
106
107 fn deref(&self) -> &Self::Target {
108 self.dir.path()
109 }
110}

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t