Fossil SCM
Never allow the "fossil open" command to proceed on a non-empty working directory unless either the --force or --keep options are used.
Commit
99ab1118f57dcaf286b12dfba1beeaa9ea7f3f95764238037600f06051c835d3
Parent
8635cb3d177e884…
1 file changed
+13
-6
M
src/db.c
+13
-6
| --- src/db.c | ||
| +++ src/db.c | ||
| @@ -3082,13 +3082,13 @@ | ||
| 3082 | 3082 | ** |
| 3083 | 3083 | ** Usage: %fossil open REPOSITORY ?VERSION? ?OPTIONS? |
| 3084 | 3084 | ** |
| 3085 | 3085 | ** Open a new connection to the repository name REPOSITORY. A checkout |
| 3086 | 3086 | ** for the repository is created with its root at the current working |
| 3087 | -** directory, or at some other directory identified by "--workdir DIR". | |
| 3088 | -** If VERSION is specified then that version is checked out. Otherwise | |
| 3089 | -** the most recent check-in on the main branch (usually "trunk") is used. | |
| 3087 | +** directory, or in DIR if the "--workdir DIR" is used. If VERSION is | |
| 3088 | +** specified then that version is checked out. Otherwise the most recent | |
| 3089 | +** check-in on the main branch (usually "trunk") is used. | |
| 3090 | 3090 | ** |
| 3091 | 3091 | ** REPOSITORY can be the filename for a repository that already exists on the |
| 3092 | 3092 | ** local machine or it can be a URI for a remote repository. If REPOSITORY |
| 3093 | 3093 | ** is a URI, the remote repo is first cloned, then the clone is opened. |
| 3094 | 3094 | ** The clone will be stored in the current directory, or in an alternative |
| @@ -3101,14 +3101,18 @@ | ||
| 3101 | 3101 | ** |
| 3102 | 3102 | ** The base URI for cloning is 'https://fossil-scm.org/home'. The extra |
| 3103 | 3103 | ** 'new-name' term means that the cloned repository will be called |
| 3104 | 3104 | ** 'new-name.fossil'. |
| 3105 | 3105 | ** |
| 3106 | +** Note that | |
| 3107 | +** | |
| 3106 | 3108 | ** Options: |
| 3107 | 3109 | ** --empty Initialize checkout as being empty, but still connected |
| 3108 | 3110 | ** with the local repository. If you commit this checkout, |
| 3109 | 3111 | ** it will become a new "initial" commit in the repository. |
| 3112 | +** --force Continue with the open even if the working directory is | |
| 3113 | +** not empy. | |
| 3110 | 3114 | ** --force-missing Force opening a repository with missing content |
| 3111 | 3115 | ** --keep Only modify the manifest and manifest.uuid files |
| 3112 | 3116 | ** --nested Allow opening a repository inside an opened checkout |
| 3113 | 3117 | ** --repodir DIR If REPOSITORY is a URI that will be cloned, store |
| 3114 | 3118 | ** the clone in DIR rather than in "." |
| @@ -3125,10 +3129,11 @@ | ||
| 3125 | 3129 | int keepFlag; |
| 3126 | 3130 | int forceMissingFlag; |
| 3127 | 3131 | int allowNested; |
| 3128 | 3132 | int allowSymlinks; |
| 3129 | 3133 | int setmtimeFlag; /* --setmtime. Set mtimes on files */ |
| 3134 | + int bForce = 0; /* --force. Open even if non-empty dir */ | |
| 3130 | 3135 | static char *azNewArgv[] = { 0, "checkout", "--prompt", 0, 0, 0, 0 }; |
| 3131 | 3136 | const char *zWorkDir; /* --workdir value */ |
| 3132 | 3137 | const char *zRepo = 0; /* Name of the repository file */ |
| 3133 | 3138 | const char *zRepoDir = 0; /* --repodir value */ |
| 3134 | 3139 | char *zPwd; /* Initial working directory */ |
| @@ -3140,10 +3145,11 @@ | ||
| 3140 | 3145 | forceMissingFlag = find_option("force-missing",0,0)!=0; |
| 3141 | 3146 | allowNested = find_option("nested",0,0)!=0; |
| 3142 | 3147 | setmtimeFlag = find_option("setmtime",0,0)!=0; |
| 3143 | 3148 | zWorkDir = find_option("workdir",0,1); |
| 3144 | 3149 | zRepoDir = find_option("repodir",0,1); |
| 3150 | + bForce = find_option("force",0,0)!=0; | |
| 3145 | 3151 | zPwd = file_getcwd(0,0); |
| 3146 | 3152 | |
| 3147 | 3153 | |
| 3148 | 3154 | /* We should be done with options.. */ |
| 3149 | 3155 | verify_all_options(); |
| @@ -3175,13 +3181,14 @@ | ||
| 3175 | 3181 | } |
| 3176 | 3182 | } |
| 3177 | 3183 | if( file_chdir(zWorkDir, 0) ){ |
| 3178 | 3184 | fossil_fatal("unable to make %s the working directory", zWorkDir); |
| 3179 | 3185 | } |
| 3180 | - }else if( keepFlag==0 && isUri && file_directory_size(".", 0, 1)>0 ){ | |
| 3181 | - fossil_fatal("directory %s is not empty\nuse \"--workdir .\" " | |
| 3182 | - "to override this error", zPwd); | |
| 3186 | + } | |
| 3187 | + if( keepFlag==0 && bForce==0 && file_directory_size(".", 0, 1)>0 ){ | |
| 3188 | + fossil_fatal("directory %s is not empty\n" | |
| 3189 | + "use the --force option to override", file_getcwd(0,0)); | |
| 3183 | 3190 | } |
| 3184 | 3191 | |
| 3185 | 3192 | if( db_open_local_v2(0, allowNested) ){ |
| 3186 | 3193 | fossil_fatal("there is already an open tree at %s", g.zLocalRoot); |
| 3187 | 3194 | } |
| 3188 | 3195 |
| --- src/db.c | |
| +++ src/db.c | |
| @@ -3082,13 +3082,13 @@ | |
| 3082 | ** |
| 3083 | ** Usage: %fossil open REPOSITORY ?VERSION? ?OPTIONS? |
| 3084 | ** |
| 3085 | ** Open a new connection to the repository name REPOSITORY. A checkout |
| 3086 | ** for the repository is created with its root at the current working |
| 3087 | ** directory, or at some other directory identified by "--workdir DIR". |
| 3088 | ** If VERSION is specified then that version is checked out. Otherwise |
| 3089 | ** the most recent check-in on the main branch (usually "trunk") is used. |
| 3090 | ** |
| 3091 | ** REPOSITORY can be the filename for a repository that already exists on the |
| 3092 | ** local machine or it can be a URI for a remote repository. If REPOSITORY |
| 3093 | ** is a URI, the remote repo is first cloned, then the clone is opened. |
| 3094 | ** The clone will be stored in the current directory, or in an alternative |
| @@ -3101,14 +3101,18 @@ | |
| 3101 | ** |
| 3102 | ** The base URI for cloning is 'https://fossil-scm.org/home'. The extra |
| 3103 | ** 'new-name' term means that the cloned repository will be called |
| 3104 | ** 'new-name.fossil'. |
| 3105 | ** |
| 3106 | ** Options: |
| 3107 | ** --empty Initialize checkout as being empty, but still connected |
| 3108 | ** with the local repository. If you commit this checkout, |
| 3109 | ** it will become a new "initial" commit in the repository. |
| 3110 | ** --force-missing Force opening a repository with missing content |
| 3111 | ** --keep Only modify the manifest and manifest.uuid files |
| 3112 | ** --nested Allow opening a repository inside an opened checkout |
| 3113 | ** --repodir DIR If REPOSITORY is a URI that will be cloned, store |
| 3114 | ** the clone in DIR rather than in "." |
| @@ -3125,10 +3129,11 @@ | |
| 3125 | int keepFlag; |
| 3126 | int forceMissingFlag; |
| 3127 | int allowNested; |
| 3128 | int allowSymlinks; |
| 3129 | int setmtimeFlag; /* --setmtime. Set mtimes on files */ |
| 3130 | static char *azNewArgv[] = { 0, "checkout", "--prompt", 0, 0, 0, 0 }; |
| 3131 | const char *zWorkDir; /* --workdir value */ |
| 3132 | const char *zRepo = 0; /* Name of the repository file */ |
| 3133 | const char *zRepoDir = 0; /* --repodir value */ |
| 3134 | char *zPwd; /* Initial working directory */ |
| @@ -3140,10 +3145,11 @@ | |
| 3140 | forceMissingFlag = find_option("force-missing",0,0)!=0; |
| 3141 | allowNested = find_option("nested",0,0)!=0; |
| 3142 | setmtimeFlag = find_option("setmtime",0,0)!=0; |
| 3143 | zWorkDir = find_option("workdir",0,1); |
| 3144 | zRepoDir = find_option("repodir",0,1); |
| 3145 | zPwd = file_getcwd(0,0); |
| 3146 | |
| 3147 | |
| 3148 | /* We should be done with options.. */ |
| 3149 | verify_all_options(); |
| @@ -3175,13 +3181,14 @@ | |
| 3175 | } |
| 3176 | } |
| 3177 | if( file_chdir(zWorkDir, 0) ){ |
| 3178 | fossil_fatal("unable to make %s the working directory", zWorkDir); |
| 3179 | } |
| 3180 | }else if( keepFlag==0 && isUri && file_directory_size(".", 0, 1)>0 ){ |
| 3181 | fossil_fatal("directory %s is not empty\nuse \"--workdir .\" " |
| 3182 | "to override this error", zPwd); |
| 3183 | } |
| 3184 | |
| 3185 | if( db_open_local_v2(0, allowNested) ){ |
| 3186 | fossil_fatal("there is already an open tree at %s", g.zLocalRoot); |
| 3187 | } |
| 3188 |
| --- src/db.c | |
| +++ src/db.c | |
| @@ -3082,13 +3082,13 @@ | |
| 3082 | ** |
| 3083 | ** Usage: %fossil open REPOSITORY ?VERSION? ?OPTIONS? |
| 3084 | ** |
| 3085 | ** Open a new connection to the repository name REPOSITORY. A checkout |
| 3086 | ** for the repository is created with its root at the current working |
| 3087 | ** directory, or in DIR if the "--workdir DIR" is used. If VERSION is |
| 3088 | ** specified then that version is checked out. Otherwise the most recent |
| 3089 | ** check-in on the main branch (usually "trunk") is used. |
| 3090 | ** |
| 3091 | ** REPOSITORY can be the filename for a repository that already exists on the |
| 3092 | ** local machine or it can be a URI for a remote repository. If REPOSITORY |
| 3093 | ** is a URI, the remote repo is first cloned, then the clone is opened. |
| 3094 | ** The clone will be stored in the current directory, or in an alternative |
| @@ -3101,14 +3101,18 @@ | |
| 3101 | ** |
| 3102 | ** The base URI for cloning is 'https://fossil-scm.org/home'. The extra |
| 3103 | ** 'new-name' term means that the cloned repository will be called |
| 3104 | ** 'new-name.fossil'. |
| 3105 | ** |
| 3106 | ** Note that |
| 3107 | ** |
| 3108 | ** Options: |
| 3109 | ** --empty Initialize checkout as being empty, but still connected |
| 3110 | ** with the local repository. If you commit this checkout, |
| 3111 | ** it will become a new "initial" commit in the repository. |
| 3112 | ** --force Continue with the open even if the working directory is |
| 3113 | ** not empy. |
| 3114 | ** --force-missing Force opening a repository with missing content |
| 3115 | ** --keep Only modify the manifest and manifest.uuid files |
| 3116 | ** --nested Allow opening a repository inside an opened checkout |
| 3117 | ** --repodir DIR If REPOSITORY is a URI that will be cloned, store |
| 3118 | ** the clone in DIR rather than in "." |
| @@ -3125,10 +3129,11 @@ | |
| 3129 | int keepFlag; |
| 3130 | int forceMissingFlag; |
| 3131 | int allowNested; |
| 3132 | int allowSymlinks; |
| 3133 | int setmtimeFlag; /* --setmtime. Set mtimes on files */ |
| 3134 | int bForce = 0; /* --force. Open even if non-empty dir */ |
| 3135 | static char *azNewArgv[] = { 0, "checkout", "--prompt", 0, 0, 0, 0 }; |
| 3136 | const char *zWorkDir; /* --workdir value */ |
| 3137 | const char *zRepo = 0; /* Name of the repository file */ |
| 3138 | const char *zRepoDir = 0; /* --repodir value */ |
| 3139 | char *zPwd; /* Initial working directory */ |
| @@ -3140,10 +3145,11 @@ | |
| 3145 | forceMissingFlag = find_option("force-missing",0,0)!=0; |
| 3146 | allowNested = find_option("nested",0,0)!=0; |
| 3147 | setmtimeFlag = find_option("setmtime",0,0)!=0; |
| 3148 | zWorkDir = find_option("workdir",0,1); |
| 3149 | zRepoDir = find_option("repodir",0,1); |
| 3150 | bForce = find_option("force",0,0)!=0; |
| 3151 | zPwd = file_getcwd(0,0); |
| 3152 | |
| 3153 | |
| 3154 | /* We should be done with options.. */ |
| 3155 | verify_all_options(); |
| @@ -3175,13 +3181,14 @@ | |
| 3181 | } |
| 3182 | } |
| 3183 | if( file_chdir(zWorkDir, 0) ){ |
| 3184 | fossil_fatal("unable to make %s the working directory", zWorkDir); |
| 3185 | } |
| 3186 | } |
| 3187 | if( keepFlag==0 && bForce==0 && file_directory_size(".", 0, 1)>0 ){ |
| 3188 | fossil_fatal("directory %s is not empty\n" |
| 3189 | "use the --force option to override", file_getcwd(0,0)); |
| 3190 | } |
| 3191 | |
| 3192 | if( db_open_local_v2(0, allowNested) ){ |
| 3193 | fossil_fatal("there is already an open tree at %s", g.zLocalRoot); |
| 3194 | } |
| 3195 |