git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH v2 10/11] worktree move: refuse to move worktrees with submodules

From
Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Date
Nov 28, 2016, 09:43 UTC
Message-ID
<20161128094319.16176-11-pclouds@gmail.com>
In-Reply-To
<20161128094319.16176-1-pclouds@gmail.com>

Submodules contains .git files with relative paths. After a worktree move, these files need to be updated or they may point to nowhere.

This is a bandage patch to make sure "worktree move" don't break people's worktrees by accident. When .git file update code is in place, this validate_no_submodules() could be removed.

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 builtin/worktree.c | 23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)
diff --git a/builtin/worktree.c b/builtin/worktree.c
index f732a74..e36e4dc 100644
--- a/builtin/worktree.c
+++ b/builtin/worktree.c
@@ -525,6 +525,27 @@ static int unlock_worktree(int ac, const char **av, const char *prefix)
 	return ret;
 }
 
+static void validate_no_submodules(const struct worktree *wt)
+{
+	struct index_state istate = {0};
+	int i, found_submodules = 0;
+
+	if (read_index_from(&istate, worktree_git_path(wt, "index")) > 0) {
+		for (i = 0; i < istate.cache_nr; i++) {
+			struct cache_entry *ce = istate.cache[i];
+
+			if (S_ISGITLINK(ce->ce_mode)) {
+				found_submodules = 1;
+				break;
+			}
+		}
+	}
+	discard_index(&istate);
+
+	if (found_submodules)
+		die(_("This working tree contains submodules and cannot be moved yet"));
+}
+
 static int move_worktree(int ac, const char **av, const char *prefix)
 {
 	struct option options[] = {
@@ -565,6 +586,8 @@ static int move_worktree(int ac, const char **av, const char *prefix)
 	if (validate_worktree(wt, 0))
 		return -1;
 
+	validate_no_submodules(wt);
+
 	if (is_directory(dst.buf)) {
 		const char *sep = find_last_dir_sep(wt->path);
 
-- 
2.8.2.524.g6ff3d78
Previous: Nguyễn Thái Ngọc DuyNext: Stefan Beller
Message 23 of 39 in “git worktree (re)move”
  1. 00/11 git worktree (re)moveNguyễn Thái Ngọc Duy, Nov 12, 2016
  2. 06/11 worktree.c: add validate_worktree()Nguyễn Thái Ngọc Duy, Nov 12, 2016
  3. 02/11 copy.c: delete unused code in copy_file()Nguyễn Thái Ngọc Duy, Nov 12, 2016
  4. 03/11 copy.c: convert bb_(p)error_msg to error(_errno)Nguyễn Thái Ngọc Duy, Nov 12, 2016
  5. 07/11 worktree.c: add update_worktree_location()Nguyễn Thái Ngọc Duy, Nov 12, 2016
  6. 01/11 copy.c: import copy_file() from busyboxNguyễn Thái Ngọc Duy, Nov 12, 2016
  7. 05/11 copy.c: convert copy_file() to copy_dir_recursively()Nguyễn Thái Ngọc Duy, Nov 12, 2016
  8. 04/11 copy.c: style fixNguyễn Thái Ngọc Duy, Nov 12, 2016
  9. 10/11 worktree move: refuse to move worktrees with submodulesNguyễn Thái Ngọc Duy, Nov 12, 2016
  10. 09/11 worktree move: accept destination as directoryNguyễn Thái Ngọc Duy, Nov 12, 2016
  11. 08/11 worktree move: new commandNguyễn Thái Ngọc Duy, Nov 12, 2016
  12. 11/11 worktree remove: new commandNguyễn Thái Ngọc Duy, Nov 12, 2016
  13. 00/11 git worktree (re)moveNguyễn Thái Ngọc Duy, Nov 28, 2016
  14. 01/11 copy.c: import copy_file() from busyboxNguyễn Thái Ngọc Duy, Nov 28, 2016
  15. 02/11 copy.c: delete unused code in copy_file()Nguyễn Thái Ngọc Duy, Nov 28, 2016
  16. 03/11 copy.c: convert bb_(p)error_msg to error(_errno)Nguyễn Thái Ngọc Duy, Nov 28, 2016
  17. 04/11 copy.c: style fixNguyễn Thái Ngọc Duy, Nov 28, 2016
  18. 05/11 copy.c: convert copy_file() to copy_dir_recursively()Nguyễn Thái Ngọc Duy, Nov 28, 2016
  19. 06/11 worktree.c: add validate_worktree()Nguyễn Thái Ngọc Duy, Nov 28, 2016
  20. 07/11 worktree.c: add update_worktree_location()Nguyễn Thái Ngọc Duy, Nov 28, 2016
  21. 08/11 worktree move: new commandNguyễn Thái Ngọc Duy, Nov 28, 2016
  22. 09/11 worktree move: accept destination as directoryNguyễn Thái Ngọc Duy, Nov 28, 2016
  23. 10/11 worktree move: refuse to move worktrees with submodulesNguyễn Thái Ngọc Duy, Nov 28, 2016
  24. Stefan BellerDec 19, 2016
  25. 11/11 worktree remove: new commandNguyễn Thái Ngọc Duy, Nov 28, 2016
  26. Junio C HamanoNov 28, 2016
  27. Junio C HamanoNov 28, 2016
  28. Johannes SixtNov 28, 2016
  29. Duy NguyenNov 29, 2016
  30. Duy NguyenNov 29, 2016
  31. Duy NguyenNov 29, 2016
  32. Junio C HamanoNov 29, 2016
  33. Stefan BellerNov 30, 2016
  34. Johannes SixtNov 29, 2016
  35. Duy NguyenNov 30, 2016
  36. Duy NguyenNov 16, 2016
  37. Duy NguyenNov 16, 2016
  38. Junio C HamanoNov 16, 2016
  39. Junio C HamanoNov 16, 2016

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.