Fossil SCM

The "fossil open" command now tolerates the repository file being in the check-out directory without requiring the -f flag. See [forum:/forumpost/bc5f8f6e59|forum post bc5f8f6e59] for the discussion.

drh 2021-04-06 10:47 trunk
Commit 61132cefacba2ea1396ba782f3e2d2385e2a1bee9cdcc889f7f78510a5ce9214
2 files changed +6 -1 +34
+6 -1
--- src/db.c
+++ src/db.c
@@ -3488,10 +3488,11 @@
34883488
const char *zWorkDir; /* --workdir value */
34893489
const char *zRepo = 0; /* Name of the repository file */
34903490
const char *zRepoDir = 0; /* --repodir value */
34913491
char *zPwd; /* Initial working directory */
34923492
int isUri = 0; /* True if REPOSITORY is a URI */
3493
+ int nLocal; /* Number of preexisting files in cwd */
34933494
34943495
url_proxy_options();
34953496
emptyFlag = find_option("empty",0,0)!=0;
34963497
keepFlag = find_option("keep",0,0)!=0;
34973498
forceMissingFlag = find_option("force-missing",0,0)!=0;
@@ -3534,11 +3535,15 @@
35343535
}
35353536
if( file_chdir(zWorkDir, 0) ){
35363537
fossil_fatal("unable to make %s the working directory", zWorkDir);
35373538
}
35383539
}
3539
- if( keepFlag==0 && bForce==0 && file_directory_size(".", 0, 1)>0 ){
3540
+ if( keepFlag==0
3541
+ && bForce==0
3542
+ && (nLocal = file_directory_size(".", 0, 1))>0
3543
+ && (nLocal>1 || isUri || !file_in_cwd(zRepo))
3544
+ ){
35403545
fossil_fatal("directory %s is not empty\n"
35413546
"use the -f or --force option to override", file_getcwd(0,0));
35423547
}
35433548
35443549
if( db_open_local_v2(0, allowNested) ){
35453550
--- src/db.c
+++ src/db.c
@@ -3488,10 +3488,11 @@
3488 const char *zWorkDir; /* --workdir value */
3489 const char *zRepo = 0; /* Name of the repository file */
3490 const char *zRepoDir = 0; /* --repodir value */
3491 char *zPwd; /* Initial working directory */
3492 int isUri = 0; /* True if REPOSITORY is a URI */
 
3493
3494 url_proxy_options();
3495 emptyFlag = find_option("empty",0,0)!=0;
3496 keepFlag = find_option("keep",0,0)!=0;
3497 forceMissingFlag = find_option("force-missing",0,0)!=0;
@@ -3534,11 +3535,15 @@
3534 }
3535 if( file_chdir(zWorkDir, 0) ){
3536 fossil_fatal("unable to make %s the working directory", zWorkDir);
3537 }
3538 }
3539 if( keepFlag==0 && bForce==0 && file_directory_size(".", 0, 1)>0 ){
 
 
 
 
3540 fossil_fatal("directory %s is not empty\n"
3541 "use the -f or --force option to override", file_getcwd(0,0));
3542 }
3543
3544 if( db_open_local_v2(0, allowNested) ){
3545
--- src/db.c
+++ src/db.c
@@ -3488,10 +3488,11 @@
3488 const char *zWorkDir; /* --workdir value */
3489 const char *zRepo = 0; /* Name of the repository file */
3490 const char *zRepoDir = 0; /* --repodir value */
3491 char *zPwd; /* Initial working directory */
3492 int isUri = 0; /* True if REPOSITORY is a URI */
3493 int nLocal; /* Number of preexisting files in cwd */
3494
3495 url_proxy_options();
3496 emptyFlag = find_option("empty",0,0)!=0;
3497 keepFlag = find_option("keep",0,0)!=0;
3498 forceMissingFlag = find_option("force-missing",0,0)!=0;
@@ -3534,11 +3535,15 @@
3535 }
3536 if( file_chdir(zWorkDir, 0) ){
3537 fossil_fatal("unable to make %s the working directory", zWorkDir);
3538 }
3539 }
3540 if( keepFlag==0
3541 && bForce==0
3542 && (nLocal = file_directory_size(".", 0, 1))>0
3543 && (nLocal>1 || isUri || !file_in_cwd(zRepo))
3544 ){
3545 fossil_fatal("directory %s is not empty\n"
3546 "use the -f or --force option to override", file_getcwd(0,0));
3547 }
3548
3549 if( db_open_local_v2(0, allowNested) ){
3550
+34
--- src/file.c
+++ src/file.c
@@ -1366,10 +1366,11 @@
13661366
fossil_print(" file_isexe(RepoFILE) = %d\n", file_isexe(zPath,RepoFILE));
13671367
fossil_print(" file_isdir(RepoFILE) = %d\n", file_isdir(zPath,RepoFILE));
13681368
fossil_print(" file_is_repository = %d\n", file_is_repository(zPath));
13691369
fossil_print(" file_is_reserved_name = %d\n",
13701370
file_is_reserved_name(zFull,-1));
1371
+ fossil_print(" file_in_cwd = %d\n", file_in_cwd(zPath));
13711372
blob_reset(&x);
13721373
if( reset ) resetStat();
13731374
}
13741375
13751376
/*
@@ -1695,10 +1696,43 @@
16951696
fossil_print("%s\n", blob_buffer(&x));
16961697
blob_reset(&x);
16971698
}
16981699
}
16991700
}
1701
+
1702
+/*
1703
+** zFile is the name of a file. Return true if that file is in the
1704
+** current working directory (the "pwd" or file_getcwd() directory).
1705
+** Return false if the file is someplace else.
1706
+*/
1707
+int file_in_cwd(const char *zFile){
1708
+ char *zFull = file_canonical_name_dup(zFile);
1709
+ char *zCwd = file_getcwd(0,0);
1710
+ size_t nCwd = strlen(zCwd);
1711
+ size_t nFull = strlen(zFull);
1712
+ int rc = 1;
1713
+ int (*xCmp)(const char*,const char*,int);
1714
+
1715
+ if( filenames_are_case_sensitive() ){
1716
+ xCmp = fossil_strncmp;
1717
+ }else{
1718
+ xCmp = fossil_strnicmp;
1719
+ }
1720
+
1721
+ if( nFull>nCwd+1
1722
+ && xCmp(zFull,zCwd,nCwd)==0
1723
+ && zFull[nCwd]=='/'
1724
+ && strchr(zFull+nCwd+1, '/')==0
1725
+ ){
1726
+ rc = 1;
1727
+ }else{
1728
+ rc = 0;
1729
+ }
1730
+ fossil_free(zFull);
1731
+ fossil_free(zCwd);
1732
+ return rc;
1733
+}
17001734
17011735
/*
17021736
** Parse a URI into scheme, host, port, and path.
17031737
*/
17041738
void file_parse_uri(
17051739
--- src/file.c
+++ src/file.c
@@ -1366,10 +1366,11 @@
1366 fossil_print(" file_isexe(RepoFILE) = %d\n", file_isexe(zPath,RepoFILE));
1367 fossil_print(" file_isdir(RepoFILE) = %d\n", file_isdir(zPath,RepoFILE));
1368 fossil_print(" file_is_repository = %d\n", file_is_repository(zPath));
1369 fossil_print(" file_is_reserved_name = %d\n",
1370 file_is_reserved_name(zFull,-1));
 
1371 blob_reset(&x);
1372 if( reset ) resetStat();
1373 }
1374
1375 /*
@@ -1695,10 +1696,43 @@
1695 fossil_print("%s\n", blob_buffer(&x));
1696 blob_reset(&x);
1697 }
1698 }
1699 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1700
1701 /*
1702 ** Parse a URI into scheme, host, port, and path.
1703 */
1704 void file_parse_uri(
1705
--- src/file.c
+++ src/file.c
@@ -1366,10 +1366,11 @@
1366 fossil_print(" file_isexe(RepoFILE) = %d\n", file_isexe(zPath,RepoFILE));
1367 fossil_print(" file_isdir(RepoFILE) = %d\n", file_isdir(zPath,RepoFILE));
1368 fossil_print(" file_is_repository = %d\n", file_is_repository(zPath));
1369 fossil_print(" file_is_reserved_name = %d\n",
1370 file_is_reserved_name(zFull,-1));
1371 fossil_print(" file_in_cwd = %d\n", file_in_cwd(zPath));
1372 blob_reset(&x);
1373 if( reset ) resetStat();
1374 }
1375
1376 /*
@@ -1695,10 +1696,43 @@
1696 fossil_print("%s\n", blob_buffer(&x));
1697 blob_reset(&x);
1698 }
1699 }
1700 }
1701
1702 /*
1703 ** zFile is the name of a file. Return true if that file is in the
1704 ** current working directory (the "pwd" or file_getcwd() directory).
1705 ** Return false if the file is someplace else.
1706 */
1707 int file_in_cwd(const char *zFile){
1708 char *zFull = file_canonical_name_dup(zFile);
1709 char *zCwd = file_getcwd(0,0);
1710 size_t nCwd = strlen(zCwd);
1711 size_t nFull = strlen(zFull);
1712 int rc = 1;
1713 int (*xCmp)(const char*,const char*,int);
1714
1715 if( filenames_are_case_sensitive() ){
1716 xCmp = fossil_strncmp;
1717 }else{
1718 xCmp = fossil_strnicmp;
1719 }
1720
1721 if( nFull>nCwd+1
1722 && xCmp(zFull,zCwd,nCwd)==0
1723 && zFull[nCwd]=='/'
1724 && strchr(zFull+nCwd+1, '/')==0
1725 ){
1726 rc = 1;
1727 }else{
1728 rc = 0;
1729 }
1730 fossil_free(zFull);
1731 fossil_free(zCwd);
1732 return rc;
1733 }
1734
1735 /*
1736 ** Parse a URI into scheme, host, port, and path.
1737 */
1738 void file_parse_uri(
1739

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button