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

Re: [PATCH 00/11] git worktree (re)move

From
Duy Nguyen <pclouds@gmail.com>
Date
Nov 16, 2016, 13:05 UTC
Message-ID
<20161116130533.GA5393@ash>
In-Reply-To
<xmqqa8d4yts7.fsf@gitster.mtv.corp.google.com>
On Sat, Nov 12, 2016 at 06:53:44PM -0800, Junio C Hamano wrote:
Show 14 quoted lines
> not ok 12 - move worktree
> #	
> #		git worktree move source destination &&
> #		test_path_is_missing source &&
> #		git worktree list --porcelain | grep "^worktree" >actual &&
> #		cat <<-EOF >expected &&
> #		worktree $TRASH_DIRECTORY
> #		worktree $TRASH_DIRECTORY/destination
> #		worktree $TRASH_DIRECTORY/elsewhere
> #		EOF
> #		test_cmp expected actual &&
> #		git -C destination log --format=%s >actual2 &&
> #		echo init >expected2 &&
> #		test_cmp expected2 actual2

I think I've seen this (i.e. 'expected' and 'actual' differ only in the order of items) once after a rebase and ignored it, assuming something was changed during the rebase that caused this.

The following patch should fix it if that's the same thing you saw. I could pile it on worktree-move series, or you can make it a separate one-patch series. What's your preference?

-- 8< --
Subject: [PATCH] worktree list: keep the list sorted

It makes it easier to write tests for. But it should also be good for the user since locating a worktree by eye would be easier once they notice this.

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 worktree.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)
diff --git a/worktree.c b/worktree.c
index f7869f8..fe92d6f 100644
--- a/worktree.c
+++ b/worktree.c
@@ -173,6 +173,13 @@ static void mark_current_worktree(struct worktree **worktrees)
 	free(git_dir);
 }
 
+static int compare_worktree(const void *a_, const void *b_)
+{
+	const struct worktree *const *a = a_;
+	const struct worktree *const *b = b_;
+	return fspathcmp((*a)->path, (*b)->path);
+}
+
 struct worktree **get_worktrees(void)
 {
 	struct worktree **list = NULL;
@@ -205,6 +212,11 @@ struct worktree **get_worktrees(void)
 	ALLOC_GROW(list, counter + 1, alloc);
 	list[counter] = NULL;
 
+	/*
+	 * don't sort the first item (main worktree), which will
+	 * always be the first
+	 */
+	qsort(list + 1, counter - 1, sizeof(*list), compare_worktree);
 	mark_current_worktree(list);
 	return list;
 }
-- 
2.8.2.524.g6ff3d78

-- 8< --
Previous: Duy NguyenNext: Duy Nguyen
Message 36 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.