File tree Expand file tree Collapse file tree 4 files changed +37
-2
lines changed
snapshots/porcelain/tool/organize Expand file tree Collapse file tree 4 files changed +37
-2
lines changed Original file line number Diff line number Diff line change
1
+ use std:: borrow:: Cow ;
1
2
use std:: {
2
3
ffi:: OsStr ,
3
4
path:: { Path , PathBuf } ,
@@ -198,9 +199,17 @@ fn handle(
198
199
destination. display( )
199
200
) ) ,
200
201
Mode :: Execute => {
201
- if destination. starts_with ( git_workdir) {
202
+ if destination. starts_with (
203
+ git_workdir
204
+ . canonicalize ( )
205
+ . ok ( )
206
+ . map ( Cow :: Owned )
207
+ . unwrap_or ( Cow :: Borrowed ( git_workdir) ) ,
208
+ ) {
202
209
let tempdir = tempfile:: tempdir_in ( canonicalized_destination) ?;
203
- let tempdest = tempdir. path ( ) . join ( destination. file_name ( ) . expect ( "repo destination is not the root" ) ) ;
210
+ let tempdest = tempdir
211
+ . path ( )
212
+ . join ( destination. file_name ( ) . expect ( "repo destination is not the root" ) ) ;
204
213
std:: fs:: rename ( git_workdir, & tempdest) ?;
205
214
std:: fs:: create_dir_all ( destination. parent ( ) . expect ( "repo destination is not the root" ) ) ?;
206
215
std:: fs:: rename ( & tempdest, & destination) ?;
Original file line number Diff line number Diff line change @@ -139,6 +139,24 @@ title "Porcelain ${kind}"
139
139
expect_run_sh $SUCCESSFULLY ' find . -maxdepth 2 | sort'
140
140
}
141
141
)
142
+
143
+ (with " --execute with move into subdirectory of itself"
144
+ (cd example.com
145
+ rm -Rf a-repo-with-extension origin-and-fork
146
+ mv one-origin ../
147
+ cd ..
148
+ rmdir example.com && mv one-origin example.com
149
+ )
150
+ it " succeeds" && {
151
+ WITH_SNAPSHOT=" $snapshot /execute-success-new-root" \
152
+ expect_run_sh $SUCCESSFULLY " $exe tool organize --execute 2>/dev/null"
153
+ }
154
+
155
+ it " does alter the directory structure as these are already in place" && {
156
+ WITH_SNAPSHOT=" $snapshot /directory-structure-after-organize-to-new-root" \
157
+ expect_run_sh $SUCCESSFULLY ' find . -maxdepth 2 -type d | sort'
158
+ }
159
+ )
142
160
)
143
161
if test " $kind " ! = " max-pure" ; then
144
162
(with " running with no further arguments"
Original file line number Diff line number Diff line change
1
+ .
2
+ ./dir
3
+ ./example.com
4
+ ./example.com/one-origin
5
+ ./no-origin
6
+ ./no-origin/.git
7
+ ./special-origin
8
+ ./special-origin/.git
You can’t perform that action at this time.
0 commit comments