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

Re: [PATCH 10/10] worktree: add "remove" command

From
Eric Sunshine <sunshine@sunshineco.com>
Date
Aug 1, 2017, 18:24 UTC
Message-ID
<CAPig+cSV9_6j6Nkptma3BewKW8QQcem7gwFCb42VBW4Xe0Vr2w@mail.gmail.com>
In-Reply-To
<20160625075433.4608-11-pclouds@gmail.com>
On Sat, Jun 25, 2016 at 3:54 AM, Nguyễn Thái Ngọc Duy <pclouds@gmail.com> wrote:
Show 16 quoted lines
> Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
> ---
> diff --git a/builtin/worktree.c b/builtin/worktree.c
> @@ -600,6 +601,81 @@ static int move_worktree(int ac, const char **av, const char *prefix)
> +static int remove_worktree(int ac, const char **av, const char *prefix)
> +{
> +       worktrees = get_worktrees();
> +       wt = find_worktree(worktrees, prefix, av[0]);
> +       if (!wt)
> +               die(_("'%s' is not a working directory"), av[0]);
> +       if (is_main_worktree(wt))
> +               die(_("'%s' is a main working directory"), av[0]);
> +       if ((reason = is_worktree_locked(wt))) {
> +               if (*reason)
> +                       die(_("already locked, reason: %s"), reason);
> +               die(_("already locked, no reason"));

"already locked" makes sense for 'worktree lock' command, but not here. A simple "locked" would be clearer.

> +       }
> +       if (validate_worktree(wt, 0))
> +               return -1;
Leaking 'worktrees'. free_worktrees(...) recommended.
Show 22 quoted lines
> +       strbuf_addstr(&sb, wt->path);
> +       if (remove_dir_recursively(&sb, 0)) {
> +               error_errno(_("failed to delete '%s'"), sb.buf);
> +               ret = -1;
> +       }
> +       strbuf_reset(&sb);
> +       strbuf_addstr(&sb, git_common_path("worktrees/%s", wt->id));
> +       if (remove_dir_recursively(&sb, 0)) {
> +               error_errno(_("failed to delete '%s'"), sb.buf);
> +               ret = -1;
> +       }
> +       strbuf_release(&sb);
> +       free_worktrees(worktrees);
> +       return ret;
> +}
> diff --git a/t/t2028-worktree-move.sh b/t/t2028-worktree-move.sh
> @@ -89,4 +89,30 @@ test_expect_success 'move main worktree' '
> +test_expect_success 'remove locked worktree' '
> +       git worktree lock destination &&
> +       test_must_fail git worktree remove destination &&
> +       git worktree unlock destination
> +'
'unlock' within test_when_finished(), perhaps?
Show 7 quoted lines
> +test_expect_success 'remove worktree with dirty tracked file' '
> +       echo dirty >>destination/init.t &&
> +       test_must_fail git worktree remove destination
> +'
> +
> +test_expect_success 'remove worktree with untracked file' '
> +       git -C destination checkout init.t &&

Perhaps this reversion of 'init.t' belongs in the preceding test which modified it (wrapped in test_when_finished())?

Show 8 quoted lines
> +       : >destination/untracked &&
> +       test_must_fail git worktree remove destination
> +'
> +
> +test_expect_success 'force remove worktree with untracked file' '
> +       git worktree remove --force destination &&
> +       test_path_is_missing destination
> +'
Previous: Nguyễn Thái Ngọc DuyNext: Nguyễn Thái Ngọc Duy
Message 9 of 16 in “git worktree (re)move”
  1. 00/10 git worktree (re)moveNguyễn Thái Ngọc Duy, Jun 25, 2016
  2. 04/10 copy.c: style fixNguyễn Thái Ngọc Duy, Jun 25, 2016
  3. 02/10 copy.c: delete unused code in copy_file()Nguyễn Thái Ngọc Duy, Jun 25, 2016
  4. 09/10 worktree move: accept destination as directoryNguyễn Thái Ngọc Duy, Jun 25, 2016
  5. 05/10 copy.c: convert copy_file() to copy_dir_recursively()Nguyễn Thái Ngọc Duy, Jun 25, 2016
  6. Eric SunshineAug 1, 2017
  7. 01/10 copy.c: import copy_file() from busyboxNguyễn Thái Ngọc Duy, Jun 25, 2016
  8. 10/10 worktree: add "remove" commandNguyễn Thái Ngọc Duy, Jun 25, 2016
  9. Eric SunshineAug 1, 2017
  10. 06/10 worktree.c: add validate_worktree()Nguyễn Thái Ngọc Duy, Jun 25, 2016
  11. 08/10 worktree: add "move" commmandNguyễn Thái Ngọc Duy, Jun 25, 2016
  12. Eric SunshineAug 1, 2017
  13. 07/10 worktree.c: add update_worktree_location()Nguyễn Thái Ngọc Duy, Jun 25, 2016
  14. Eric SunshineAug 1, 2017
  15. 03/10 copy.c: convert bb_(p)error_msg to error(_errno)Nguyễn Thái Ngọc Duy, Jun 25, 2016
  16. Duy NguyenJul 23, 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.