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.
Commit
61132cefacba2ea1396ba782f3e2d2385e2a1bee9cdcc889f7f78510a5ce9214
Parent
63ed857ad86ad0f…
2 files changed
+6
-1
+34
M
src/db.c
+6
-1
| --- src/db.c | ||
| +++ src/db.c | ||
| @@ -3488,10 +3488,11 @@ | ||
| 3488 | 3488 | const char *zWorkDir; /* --workdir value */ |
| 3489 | 3489 | const char *zRepo = 0; /* Name of the repository file */ |
| 3490 | 3490 | const char *zRepoDir = 0; /* --repodir value */ |
| 3491 | 3491 | char *zPwd; /* Initial working directory */ |
| 3492 | 3492 | int isUri = 0; /* True if REPOSITORY is a URI */ |
| 3493 | + int nLocal; /* Number of preexisting files in cwd */ | |
| 3493 | 3494 | |
| 3494 | 3495 | url_proxy_options(); |
| 3495 | 3496 | emptyFlag = find_option("empty",0,0)!=0; |
| 3496 | 3497 | keepFlag = find_option("keep",0,0)!=0; |
| 3497 | 3498 | forceMissingFlag = find_option("force-missing",0,0)!=0; |
| @@ -3534,11 +3535,15 @@ | ||
| 3534 | 3535 | } |
| 3535 | 3536 | if( file_chdir(zWorkDir, 0) ){ |
| 3536 | 3537 | fossil_fatal("unable to make %s the working directory", zWorkDir); |
| 3537 | 3538 | } |
| 3538 | 3539 | } |
| 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 | + ){ | |
| 3540 | 3545 | fossil_fatal("directory %s is not empty\n" |
| 3541 | 3546 | "use the -f or --force option to override", file_getcwd(0,0)); |
| 3542 | 3547 | } |
| 3543 | 3548 | |
| 3544 | 3549 | if( db_open_local_v2(0, allowNested) ){ |
| 3545 | 3550 |
| --- 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 @@ | ||
| 1366 | 1366 | fossil_print(" file_isexe(RepoFILE) = %d\n", file_isexe(zPath,RepoFILE)); |
| 1367 | 1367 | fossil_print(" file_isdir(RepoFILE) = %d\n", file_isdir(zPath,RepoFILE)); |
| 1368 | 1368 | fossil_print(" file_is_repository = %d\n", file_is_repository(zPath)); |
| 1369 | 1369 | fossil_print(" file_is_reserved_name = %d\n", |
| 1370 | 1370 | file_is_reserved_name(zFull,-1)); |
| 1371 | + fossil_print(" file_in_cwd = %d\n", file_in_cwd(zPath)); | |
| 1371 | 1372 | blob_reset(&x); |
| 1372 | 1373 | if( reset ) resetStat(); |
| 1373 | 1374 | } |
| 1374 | 1375 | |
| 1375 | 1376 | /* |
| @@ -1695,10 +1696,43 @@ | ||
| 1695 | 1696 | fossil_print("%s\n", blob_buffer(&x)); |
| 1696 | 1697 | blob_reset(&x); |
| 1697 | 1698 | } |
| 1698 | 1699 | } |
| 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 | +} | |
| 1700 | 1734 | |
| 1701 | 1735 | /* |
| 1702 | 1736 | ** Parse a URI into scheme, host, port, and path. |
| 1703 | 1737 | */ |
| 1704 | 1738 | void file_parse_uri( |
| 1705 | 1739 |
| --- 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 |