Commit Diff


commit - 5a896ffda48c93e29d96e89c729c62464062d61640885316455cd448ea6e5a94
commit + fec5686e57f9cf7590daa1e97e320421792dd28c95353ee7c13f0388a0f0863e
blob - 1e02b78d86555a857fae7c84a7c32d9365b10fe2b19a629891c1e507a8231228
blob + 3c2ad916f782cb485930d0941f6b75e62d49ea1af061223445f86a89d89f3673
--- cvg/cvg.c	
+++ cvg/cvg.c	
@@ -6777,7 +6777,7 @@ cmd_remove(int argc, char *argv[])
 
 	error = got_worktree_schedule_delete(worktree, &paths,
 	    delete_local_mods, status_codes, print_remove_status, NULL,
-	    repo, keep_on_disk, ignore_missing_paths);
+	    repo, keep_on_disk, ignore_missing_paths, 0);
 done:
 	if (repo) {
 		const struct got_error *close_err = got_repo_close(repo);
blob - 0696309c9d24e61629af2d72a03e77fe73c60eb8bd51cfec29a4987302aa9067
blob + 4012a5eaf316d1f5f9c64e5617317635c0a5665a9eb22262594f7d3bf29126f1
--- got/got.1	
+++ got/got.1	
@@ -1918,7 +1918,7 @@ is a directory.
 .Ar path ...
 .Xc
 .Dl Pq alias: Cm rm
-Remove versioned files from a work tree and schedule them for deletion
+Remove files from a work tree and schedule versioned files for deletion
 from the repository in the next commit.
 .Pp
 By default, only files tracked under version control are removed, and
@@ -1954,7 +1954,14 @@ The following status codes may be specified:
 .Fl f
 option)
 .It ! Ta versioned file expected on disk but missing
+.It ? Ta unversioned file (deletion is permanent!)
 .El
+.Pp
+The
+.Fl s\ ?
+option in combination with
+.Fl k
+results in a no-op since the unversioned files will be kept on disk.
 .El
 .Tg pa
 .It Xo
blob - 439c74533638a4717e2b7dd052341b47136155a011c3967008eaed24fa53fce8
blob + 12336d47c4b8eafffd8514ecc20e19c403a9729d6c18df82b5255e66eeae1954
--- got/got.c	
+++ got/got.c	
@@ -8441,7 +8441,7 @@ cmd_remove(int argc, char *argv[])
 	struct got_pathlist_head paths;
 	struct got_pathlist_entry *pe;
 	int ch, delete_local_mods = 0, can_recurse = 0, keep_on_disk = 0, i;
-	int ignore_missing_paths = 0;
+	int ignore_missing_paths = 0, delete_unversioned = 0;
 	int *pack_fds = NULL;
 
 	RB_INIT(&paths);
@@ -8473,6 +8473,9 @@ cmd_remove(int argc, char *argv[])
 				case GOT_STATUS_MISSING:
 					ignore_missing_paths = 1;
 					break;
+				case GOT_STATUS_UNVERSIONED:
+					delete_unversioned = 1;
+					break;
 				default:
 					errx(1, "invalid status code '%c'",
 					    optarg[i]);
@@ -8554,7 +8557,7 @@ cmd_remove(int argc, char *argv[])
 
 	error = got_worktree_schedule_delete(worktree, &paths,
 	    delete_local_mods, status_codes, print_remove_status, NULL,
-	    repo, keep_on_disk, ignore_missing_paths);
+	    repo, keep_on_disk, ignore_missing_paths, delete_unversioned);
 done:
 	if (repo) {
 		const struct got_error *close_err = got_repo_close(repo);
blob - 4513112b75aa78380e5c34d41882d63dd15070bc3581e4b317bf1eb81f4e70aa
blob + b30ccae318b9206107747dc67f22258dee0ff035cc0aae87abc5a385fb8eec33
--- include/got_worktree.h	
+++ include/got_worktree.h	
@@ -238,7 +238,7 @@ const struct got_error *got_worktree_schedule_add(stru
 const struct got_error *
 got_worktree_schedule_delete(struct got_worktree *,
     struct got_pathlist_head *, int, const char *,
-    got_worktree_delete_cb, void *, struct got_repository *, int, int);
+    got_worktree_delete_cb, void *, struct got_repository *, int, int, int);
 
 /* A callback function which is used to select or reject a patch. */
 typedef const struct got_error *(*got_worktree_patch_cb)(int *, void *,
blob - 198235d3bedddf3b7ae247dafb920b72ee87520f443972ac253e94c2171b5a61
blob + 235d42bcc1fd7657827eff9516d4174f8df58c27e1bc34e765bcada360eba92a
--- lib/worktree.c	
+++ lib/worktree.c	
@@ -4554,6 +4554,7 @@ struct schedule_deletion_args {
 	int delete_local_mods;
 	int keep_on_disk;
 	int ignore_missing_paths;
+	int delete_unversioned;
 	const char *status_path;
 	size_t status_path_len;
 	const char *status_codes;
@@ -4580,28 +4581,32 @@ schedule_for_deletion(void *arg, unsigned char status,
 	if (status == GOT_STATUS_UNVERSIONED) {
 		if (a->keep_on_disk)
 			return NULL;
-		return got_error_path(relpath, GOT_ERR_FILE_STATUS);
-	}
+		if (!a->delete_unversioned)
+			return got_error_path(relpath, GOT_ERR_FILE_STATUS);
+	} else {
+		ie = got_fileindex_entry_get(a->fileindex, relpath,
+		    strlen(relpath));
+		if (ie == NULL)
+			return got_error_path(relpath, GOT_ERR_FILE_STATUS);
 
-	ie = got_fileindex_entry_get(a->fileindex, relpath, strlen(relpath));
-	if (ie == NULL)
-		return got_error_path(relpath, GOT_ERR_FILE_STATUS);
-
-	staged_status = get_staged_status(ie);
-	if (staged_status != GOT_STATUS_NO_CHANGE) {
-		if (staged_status == GOT_STATUS_DELETE)
-			return NULL;
-		return got_error_path(relpath, GOT_ERR_FILE_STAGED);
+		staged_status = get_staged_status(ie);
+		if (staged_status != GOT_STATUS_NO_CHANGE) {
+			if (staged_status == GOT_STATUS_DELETE)
+				return NULL;
+			return got_error_path(relpath, GOT_ERR_FILE_STAGED);
+		}
 	}
 
 	if (asprintf(&ondisk_path, "%s/%s", a->worktree->root_path,
 	    relpath) == -1)
 		return got_error_from_errno("asprintf");
 
-	err = get_file_status(&status, &sb, ie, ondisk_path, dirfd, de_name,
-	    a->repo);
-	if (err)
-		goto done;
+	if (ie) {
+		err = get_file_status(&status, &sb, ie, ondisk_path, dirfd, de_name,
+		    a->repo);
+		if (err)
+			goto done;
+	}
 
 	if (a->status_codes) {
 		size_t ncodes = strlen(a->status_codes);
@@ -4616,7 +4621,8 @@ schedule_for_deletion(void *arg, unsigned char status,
 			return NULL;
 		}
 		if (a->status_codes[i] != GOT_STATUS_MODIFY &&
-		    a->status_codes[i] != GOT_STATUS_MISSING) {
+		    a->status_codes[i] != GOT_STATUS_MISSING &&
+		    a->status_codes[i] != GOT_STATUS_UNVERSIONED) {
 			static char msg[64];
 			snprintf(msg, sizeof(msg),
 			    "invalid status code '%c'", a->status_codes[i]);
@@ -4636,8 +4642,13 @@ schedule_for_deletion(void *arg, unsigned char status,
 			err = got_error_set_errno(ENOENT, relpath);
 			goto done;
 		}
+		if (status == GOT_STATUS_UNVERSIONED && !a->delete_unversioned) {
+			err = got_error_path(relpath, GOT_ERR_FILE_STATUS);
+			goto done;
+		}
 		if (status != GOT_STATUS_MODIFY &&
-		    status != GOT_STATUS_MISSING) {
+		    status != GOT_STATUS_MISSING &&
+		    status != GOT_STATUS_UNVERSIONED)  {
 			err = got_error_path(relpath, GOT_ERR_FILE_STATUS);
 			goto done;
 		}
@@ -4681,10 +4692,12 @@ schedule_for_deletion(void *arg, unsigned char status,
 		    strlen(ondisk_path), root_len) != 0);
 	}
 
-	if (got_fileindex_entry_has_blob(ie))
-		got_fileindex_entry_mark_deleted_from_disk(ie);
-	else
-		got_fileindex_entry_remove(a->fileindex, ie);
+	if (ie) {
+		if (got_fileindex_entry_has_blob(ie))
+			got_fileindex_entry_mark_deleted_from_disk(ie);
+		else
+			got_fileindex_entry_remove(a->fileindex, ie);
+	}
 done:
 	free(ondisk_path);
 	if (err)
@@ -4700,7 +4713,8 @@ got_worktree_schedule_delete(struct got_worktree *work
     struct got_pathlist_head *paths, int delete_local_mods,
     const char *status_codes,
     got_worktree_delete_cb progress_cb, void *progress_arg,
-    struct got_repository *repo, int keep_on_disk, int ignore_missing_paths)
+    struct got_repository *repo, int keep_on_disk, int ignore_missing_paths,
+    int delete_unversioned)
 {
 	struct got_fileindex *fileindex = NULL;
 	char *fileindex_path = NULL;
@@ -4725,6 +4739,7 @@ got_worktree_schedule_delete(struct got_worktree *work
 	sda.delete_local_mods = delete_local_mods;
 	sda.keep_on_disk = keep_on_disk;
 	sda.ignore_missing_paths = ignore_missing_paths;
+	sda.delete_unversioned = delete_unversioned;
 	sda.status_codes = status_codes;
 
 	RB_FOREACH(pe, got_pathlist_head, paths) {