-
Notifications
You must be signed in to change notification settings - Fork 65
Expand file tree
/
Copy pathpatch_tests.patch
More file actions
71 lines (64 loc) · 2.44 KB
/
patch_tests.patch
File metadata and controls
71 lines (64 loc) · 2.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
--- crates/opendev-runtime/src/worktree/tests.rs
+++ crates/opendev-runtime/src/worktree/tests.rs
@@ -4,6 +4,17 @@
use super::*;
+fn sanitize_path(path: PathBuf) -> PathBuf {
+ // On Windows, tempfile and canonicalize can return paths with the `\\?\` prefix.
+ // Git on Windows has issues creating internals (`.git`) when this prefix is present.
+ #[cfg(windows)]
+ {
+ let s = path.to_string_lossy();
+ if s.starts_with(r"\\?\") || s.starts_with("//?/") {
+ return PathBuf::from(&s[4..]);
+ }
+ }
+ path
+}
+
/// Create a temporary git repo for testing.
fn create_test_repo() -> TempDir {
let dir = TempDir::new().unwrap();
- let repo = dir.path().canonicalize().unwrap();
+ let repo = sanitize_path(dir.path().canonicalize().unwrap());
Command::new("git")
.args(["init"])
@@ -47,7 +58,7 @@
#[test]
fn test_create_worktree() {
let repo_dir = create_test_repo();
- let repo = repo_dir.path().canonicalize().unwrap();
+ let repo = sanitize_path(repo_dir.path().canonicalize().unwrap());
let wt_base = repo.join(".opendev/worktrees");
let mgr = WorktreeManager::new(wt_base.clone());
@@ -60,7 +71,7 @@
#[test]
fn test_cleanup_no_changes() {
let repo_dir = create_test_repo();
- let repo = repo_dir.path().canonicalize().unwrap();
+ let repo = sanitize_path(repo_dir.path().canonicalize().unwrap());
let wt_base = repo.join(".opendev/worktrees");
let mgr = WorktreeManager::new(wt_base);
@@ -74,7 +85,7 @@
#[test]
fn test_cleanup_with_changes_preserves() {
let repo_dir = create_test_repo();
- let repo = repo_dir.path().canonicalize().unwrap();
+ let repo = sanitize_path(repo_dir.path().canonicalize().unwrap());
let wt_base = repo.join(".opendev/worktrees");
let mgr = WorktreeManager::new(wt_base);
@@ -88,7 +99,7 @@
#[test]
fn test_has_changes() {
let repo_dir = create_test_repo();
- let repo = repo_dir.path().canonicalize().unwrap();
+ let repo = sanitize_path(repo_dir.path().canonicalize().unwrap());
let wt_base = repo.join(".opendev/worktrees");
let mgr = WorktreeManager::new(wt_base);
@@ -103,7 +114,7 @@
#[test]
fn test_list_worktrees() {
let repo_dir = create_test_repo();
- let repo = repo_dir.path().canonicalize().unwrap();
+ let repo = sanitize_path(repo_dir.path().canonicalize().unwrap());
let wt_base = repo.join(".opendev/worktrees");
let mgr = WorktreeManager::new(wt_base);