Commit 8f8646e5e92d5fc7ecc97732100e239380ac5de9

Stefan Sperling 2019-07-25T12:27:34

list of merged paths for rebase and histedit must not be empty

diff --git a/include/got_error.h b/include/got_error.h
index 53d9b43..d0bace4 100644
--- a/include/got_error.h
+++ b/include/got_error.h
@@ -112,6 +112,7 @@
 #define GOT_ERR_HISTEDIT_BUSY	96
 #define GOT_ERR_HISTEDIT_CMD	97
 #define GOT_ERR_HISTEDIT_PATH	98
+#define GOT_ERR_NO_MERGED_PATHS 99
 
 static const struct got_error {
 	int code;
@@ -224,6 +225,7 @@ static const struct got_error {
 	{ GOT_ERR_HISTEDIT_CMD, "bad histedit command" },
 	{ GOT_ERR_HISTEDIT_PATH, "cannot edit branch history which contains "
 	    "changes outside of this work tree's path prefix" },
+	{ GOT_ERR_NO_MERGED_PATHS, "empty list of merged paths" },
 };
 
 /*
diff --git a/lib/worktree.c b/lib/worktree.c
index cdff663..b41a123 100644
--- a/lib/worktree.c
+++ b/lib/worktree.c
@@ -4012,6 +4012,10 @@ rebase_commit(struct got_object_id **new_commit_id,
 	 */
 	if (merged_paths) {
 		struct got_pathlist_entry *pe;
+		if (TAILQ_EMPTY(merged_paths)) {
+			err = got_error(GOT_ERR_NO_MERGED_PATHS);
+			goto done;
+		}
 		TAILQ_FOREACH(pe, merged_paths, entry) {
 			err = worktree_status(worktree, pe->path, fileindex,
 			    repo, collect_commitables, &cc_arg, NULL, NULL);