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.

drh 2020-08-08 18:14 trunk
Commit 99ab1118f57dcaf286b12dfba1beeaa9ea7f3f95764238037600f06051c835d3
1 file changed +13 -6
+13 -6
--- src/db.c
+++ src/db.c
@@ -3082,13 +3082,13 @@
30823082
**
30833083
** Usage: %fossil open REPOSITORY ?VERSION? ?OPTIONS?
30843084
**
30853085
** Open a new connection to the repository name REPOSITORY. A checkout
30863086
** 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.
30903090
**
30913091
** REPOSITORY can be the filename for a repository that already exists on the
30923092
** local machine or it can be a URI for a remote repository. If REPOSITORY
30933093
** is a URI, the remote repo is first cloned, then the clone is opened.
30943094
** The clone will be stored in the current directory, or in an alternative
@@ -3101,14 +3101,18 @@
31013101
**
31023102
** The base URI for cloning is 'https://fossil-scm.org/home'. The extra
31033103
** 'new-name' term means that the cloned repository will be called
31043104
** 'new-name.fossil'.
31053105
**
3106
+** Note that
3107
+**
31063108
** Options:
31073109
** --empty Initialize checkout as being empty, but still connected
31083110
** with the local repository. If you commit this checkout,
31093111
** 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.
31103114
** --force-missing Force opening a repository with missing content
31113115
** --keep Only modify the manifest and manifest.uuid files
31123116
** --nested Allow opening a repository inside an opened checkout
31133117
** --repodir DIR If REPOSITORY is a URI that will be cloned, store
31143118
** the clone in DIR rather than in "."
@@ -3125,10 +3129,11 @@
31253129
int keepFlag;
31263130
int forceMissingFlag;
31273131
int allowNested;
31283132
int allowSymlinks;
31293133
int setmtimeFlag; /* --setmtime. Set mtimes on files */
3134
+ int bForce = 0; /* --force. Open even if non-empty dir */
31303135
static char *azNewArgv[] = { 0, "checkout", "--prompt", 0, 0, 0, 0 };
31313136
const char *zWorkDir; /* --workdir value */
31323137
const char *zRepo = 0; /* Name of the repository file */
31333138
const char *zRepoDir = 0; /* --repodir value */
31343139
char *zPwd; /* Initial working directory */
@@ -3140,10 +3145,11 @@
31403145
forceMissingFlag = find_option("force-missing",0,0)!=0;
31413146
allowNested = find_option("nested",0,0)!=0;
31423147
setmtimeFlag = find_option("setmtime",0,0)!=0;
31433148
zWorkDir = find_option("workdir",0,1);
31443149
zRepoDir = find_option("repodir",0,1);
3150
+ bForce = find_option("force",0,0)!=0;
31453151
zPwd = file_getcwd(0,0);
31463152
31473153
31483154
/* We should be done with options.. */
31493155
verify_all_options();
@@ -3175,13 +3181,14 @@
31753181
}
31763182
}
31773183
if( file_chdir(zWorkDir, 0) ){
31783184
fossil_fatal("unable to make %s the working directory", zWorkDir);
31793185
}
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));
31833190
}
31843191
31853192
if( db_open_local_v2(0, allowNested) ){
31863193
fossil_fatal("there is already an open tree at %s", g.zLocalRoot);
31873194
}
31883195
--- 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

Keyboard Shortcuts

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