git-gui: Allow 'Create New Repository' on existing directories
Often users setup a few source files and get a project rolling before they create a Git repository for it. In such cases the core Git tools allow users to initialize a new repository by simply running `git init` at the desired root level directory. We need to allow the same situation in git-gui; if the user is trying to make a new repository we should let them do that to any location they chose. If the directory already exists and already has files contained within it we still should allow the user to create a repository there. However we still need to disallow creating a repository on top of an existing repository. Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
Shawn O. Pearce committed
Jan 16, 2008 at 01:14 UTC
d36a8f73a4201ab21a553b5caa5b890b8f1d7213
1 file changed
+22
-28
lib/choose_repository.tcl
+22
-28
@@ -290,11 +290,6 @@ method _write_local_path {args} {
290
}
291
292
method _git_init {} {
293
- if {[file exists $local_path]} {
294
- error_popup [mc "Location %s already exists." $local_path]
295
- return 0
296
- }
297
-
293
if {[catch {file mkdir $local_path} err]} {
294
error_popup [strcat \
295
[mc "Failed to create repository %s:" $local_path] \
@@ -417,41 +412,35 @@ method _new_local_path {} {
412
if {$p eq {}} return
413
414
set p [file normalize $p]
420
- if {[file isdirectory $p]} {
421
- foreach i [glob \
422
- -directory $p \
423
- -tails \
424
- -nocomplain \
425
- * .*] {
426
- switch -- $i {
427
- . continue
428
- .. continue
429
- default {
430
- error_popup [mc "Directory %s already exists." $p]
431
- return
432
- }
433
- }
434
- }
435
- if {[catch {file delete $p} err]} {
436
- error_popup [strcat \
437
- [mc "Directory %s already exists." $p] \
438
- "\n\n$err"]
439
- return
440
- }
441
- } elseif {[file exists $p]} {
442
- error_popup [mc "File %s already exists." $p]
415
+ if {![_new_ok $p]} {
416
return
417
}
418
set local_path $p
419
}
420
421
method _do_new2 {} {
422
+ if {![_new_ok $local_path]} {
423
+ return
424
+ }
425
if {![_git_init $this]} {
426
return
427
}
428
set done 1
429
}
430
431
+proc _new_ok {p} {
432
+ if {[file isdirectory $p]} {
433
+ if {[_is_git [file join $p .git]]} {
434
+ error_popup [mc "Directory %s already exists." $p]
435
+ return 0
436
+ }
437
+ } elseif {[file exists $p]} {
438
+ error_popup [mc "File %s already exists." $p]
439
+ return 0
440
+ }
441
+ return 1
442
+}
443
+
444
######################################################################
445
##
446
## Clone Existing Repository
@@ -607,6 +596,11 @@ method _do_clone2 {} {
596
}
597
}
598
599
+ if {[file exists $local_path]} {
600
+ error_popup [mc "Location %s already exists." $local_path]
601
+ return
602
+ }
603
+
604
if {![_git_init $this]} return
605
set local_path [pwd]
606