commit 49520a3227e82d18f80658e593e3300434fa8625 from: Stefan Sperling date: Sat Dec 29 14:51:56 2018 UTC verify path prefix when checking out into existing work tree commit - 381be7cc5b9b3d938b44f0f30dafdecf1c2f5a6b commit + 49520a3227e82d18f80658e593e3300434fa8625 blob - 238a09f448842b25d1bc93a4f00809127c47e8a7 blob + 00586f45a6454992ba9f574c4bd6e54132bcda79 --- got/got.c +++ got/got.c @@ -283,6 +283,11 @@ cmd_checkout(int argc, char *argv[]) if (error != NULL) goto done; + if (strcmp(path_prefix, got_worktree_get_path_prefix(worktree)) != 0) { + error = got_error(GOT_ERR_PATH_PREFIX); + goto done; + } + error = got_worktree_checkout_files(worktree, repo, checkout_progress, worktree_path, checkout_cancel, NULL); if (error != NULL) blob - e7d37e6ced26afc644b84a7fc0cd12c351b63596 blob + 7720ed223a4d642bf1479c1aed2af411b2dadc87 --- include/got_error.h +++ include/got_error.h @@ -67,6 +67,7 @@ #define GOT_ERR_FILEIDX_SIG 51 #define GOT_ERR_FILEIDX_VER 52 #define GOT_ERR_FILEIDX_CSUM 53 +#define GOT_ERR_PATH_PREFIX 54 static const struct got_error { int code; @@ -122,6 +123,8 @@ static const struct got_error { { GOT_ERR_FILEIDX_SIG, "bad file index signature" }, { GOT_ERR_FILEIDX_VER, "unknown file index format version" }, { GOT_ERR_FILEIDX_CSUM, "bad file index checksum" }, + { GOT_ERR_PATH_PREFIX, "worktree already contains items from a " + "different path prefix" }, }; /* blob - aa7c545c7fa2e55ec8ce54f936a4e7138510a161 blob + 80de9bdeca406f8d4266ddd4b98a8a26f59d6df5 --- include/got_worktree.h +++ include/got_worktree.h @@ -47,6 +47,12 @@ void got_worktree_close(struct got_worktree *); char *got_worktree_get_repo_path(struct got_worktree *); /* + * Get the path prefix associated with a worktree. + * The caller must dispose of it with free(3). + */ +const char *got_worktree_get_path_prefix(struct got_worktree *); + +/* * Get the name of a work tree's HEAD reference. * The caller must dispose of it with free(3). */ blob - 1a57978e5b801e3f05e7fc89d8229263b8f664cf blob + c55f3e7519777cdce2a4f25c8e35006404281300 --- lib/worktree.c +++ lib/worktree.c @@ -374,6 +374,12 @@ char * got_worktree_get_repo_path(struct got_worktree *worktree) { return strdup(worktree->repo_path); +} + +const char * +got_worktree_get_path_prefix(struct got_worktree *worktree) +{ + return worktree->repo_path; } char *