File tree 5 files changed +42
-4
lines changed
5 files changed +42
-4
lines changed Original file line number Diff line number Diff line change @@ -90,14 +90,14 @@ impl Capabilities {
90
90
. write ( true )
91
91
. open ( & src_path) ?;
92
92
let link_path = root. join ( "__file_link" ) ;
93
- if symlink :: symlink_file ( & src_path, & link_path) . is_err ( ) {
93
+ if crate :: os :: create_symlink ( & src_path, & link_path) . is_err ( ) {
94
94
std:: fs:: remove_file ( & src_path) ?;
95
95
return Ok ( false ) ;
96
96
}
97
97
98
98
let res = std:: fs:: symlink_metadata ( & link_path) . map ( |m| m. is_symlink ( ) ) ;
99
99
let cleanup = std:: fs:: remove_file ( & src_path) ;
100
- symlink :: remove_symlink_file ( & link_path)
100
+ crate :: os :: remove_symlink ( & link_path)
101
101
. or_else ( |_| std:: fs:: remove_file ( & link_path) )
102
102
. and ( cleanup) ?;
103
103
res
Original file line number Diff line number Diff line change @@ -21,6 +21,11 @@ pub struct Options {
21
21
/// This should be enabled when cloning to avoid checks for freshness of files. This also enables
22
22
/// detection of collisions based on whether or not exclusive file creation succeeds or fails.
23
23
pub destination_is_initially_empty : bool ,
24
+ /// If true, default false, worktree entries on disk will be overwritten with content from the index
25
+ /// even if they appear to be changed. When creating directories that clash with existing worktree entries,
26
+ /// these will try to delete the existing entry.
27
+ /// This is similar in behaviour as `git checkout --force`.
28
+ pub overwrite_existing : bool ,
24
29
/// If true, default false, try to checkout as much as possible and don't abort on first error which isn't
25
30
/// due to a conflict.
26
31
/// The operation will never fail, but count the encountered errors instead along with their paths.
@@ -46,6 +51,7 @@ impl Default for Options {
46
51
keep_going : false ,
47
52
trust_ctime : true ,
48
53
check_stat : true ,
54
+ overwrite_existing : false ,
49
55
}
50
56
}
51
57
}
Original file line number Diff line number Diff line change 36
36
path : entry_path. to_owned ( ) ,
37
37
}
38
38
} ) ?) ;
39
- create_dir_all ( dest. parent ( ) . expect ( "entry paths are never empty" ) ) ?; // TODO: can this be avoided to create dirs when needed only?
39
+
40
+ let dest_dir = dest. parent ( ) . expect ( "entry paths are never empty" ) ;
41
+ create_dir_all ( dest_dir) ?; // TODO: can this be avoided to create dirs when needed only?
40
42
41
43
match entry. mode {
42
44
git_index:: entry:: Mode :: FILE | git_index:: entry:: Mode :: FILE_EXECUTABLE => {
72
74
// TODO: how to deal with mode changes? Maybe this info can be passed once we check for whether
73
75
// a checkout is needed at all.
74
76
if symlink {
75
- symlink :: symlink_auto ( symlink_destination, & dest) ?;
77
+ crate :: os :: create_symlink ( symlink_destination, & dest) ?;
76
78
} else {
77
79
std:: fs:: write ( & dest, obj. data ) ?;
78
80
}
Original file line number Diff line number Diff line change 10
10
pub mod fs;
11
11
12
12
pub mod index;
13
+
14
+ pub ( crate ) mod os;
Original file line number Diff line number Diff line change
1
+ use std:: io;
2
+ use std:: path:: Path ;
3
+
4
+ #[ cfg( not( windows) ) ]
5
+ pub fn create_symlink ( original : & Path , link : & Path ) -> io:: Result < ( ) > {
6
+ std:: os:: unix:: fs:: symlink ( original, link)
7
+ }
8
+
9
+ #[ cfg( not( windows) ) ]
10
+ pub fn remove_symlink ( path : & Path ) -> io:: Result < ( ) > {
11
+ std:: fs:: remove_file ( path)
12
+ }
13
+
14
+ #[ cfg( windows) ]
15
+ pub fn remove_symlink ( path : & Path ) -> io:: Result < ( ) > {
16
+ symlink:: remove_symlink_auto ( path)
17
+ }
18
+
19
+ #[ cfg( windows) ]
20
+ pub fn create_symlink ( original : & Path , link : & Path ) -> io:: Result < ( ) > {
21
+ use std:: os:: windows:: fs:: { symlink_dir, symlink_file} ;
22
+ // TODO: figure out if links to links count as files or whatever they point at
23
+ if std:: fs:: metadata ( link. parent ( ) . expect ( "dir for link" ) . join ( original) ) ?. is_dir ( ) {
24
+ symlink_dir ( original, link)
25
+ } else {
26
+ symlink_file ( original, original)
27
+ }
28
+ }
You can’t perform that action at this time.
0 commit comments