From patchwork Tue Jan 19 21:27:38 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rafael Silva X-Patchwork-Id: 12030863 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 36BFEC433DB for ; Tue, 19 Jan 2021 21:30:10 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id DAC8722D08 for ; Tue, 19 Jan 2021 21:30:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729449AbhASV3v (ORCPT ); Tue, 19 Jan 2021 16:29:51 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58676 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729161AbhASV3K (ORCPT ); Tue, 19 Jan 2021 16:29:10 -0500 Received: from mail-wm1-x32a.google.com (mail-wm1-x32a.google.com [IPv6:2a00:1450:4864:20::32a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5A2DFC061796 for ; Tue, 19 Jan 2021 13:28:22 -0800 (PST) Received: by mail-wm1-x32a.google.com with SMTP id v184so1040603wma.1 for ; Tue, 19 Jan 2021 13:28:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=YmQ+BE2KU76AhU11jUK+D8ysRFHmxCZr03Qr/BS8cCM=; b=AFMYiurio5CIaR/yIGjx/um6YTVtwK9gjfSioMtlg4m8a8h5B0hbDuzh/pEUlpgyhG mb9PFnQKNnPt22S3BK2e73/mFvyuaqVRgfFHxGocp0QMOZEkxcdIieodr3Foea+hCTRh tx3r8hf9fSinfolM3qev3og1P9sS71Eh0AGTcUywwcDbAkFuPJMkOwEyBpxfJ8JHXKAU wfC+QJMnPMB5oRfZgLFbSZqwq7IeCxN6ZbPf43mxkFFtVPgzmrO46ckmN5e+PN4SncAH d6B1xfELuHpXNiE8gdFM9F2pm0xRgQjRCjvdsK1OdWAvf/I6i8cfnbe/ggYbdvDkBFsV YRBw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=YmQ+BE2KU76AhU11jUK+D8ysRFHmxCZr03Qr/BS8cCM=; b=PNq+GN+nfUe/BGkcbkPBAjumdwtKuMnoHWadDt6eMN9xVizZd4jW7+nmYqV+EUmEJ5 RcMyYEsYfU6ycog7XpOGGB5wFRiBgfnALaFWvbZ9WBxAUPohA3Vax5CBh3gAzdHcDATy 2aP4oBra0eztPr+o+vTt7PzLAF5N1gU7oyjW26h2ngVNdpMX3pAzjFWcyprXlNqwq9fa OpIUI7G07oFz0Ezv9gUxF2C9l7J1JCKb4uL/yyNx3euKHj0Vlir5MFQoXYgvCyCKI7qP N15FzV2gll+ARe0pjz1wj1ur4+aL3n+KsKlYDH/drT17U6DcunbSq7mws8Euz+h/ZvuB jh/g== X-Gm-Message-State: AOAM530CCqad2471KmkWFmejFGrmjBlzV5lPfJRxHS7Rs7o24r8Nnda6 lswM5RJmMyhsc3m+gehf7tVw2ZUBde0= X-Google-Smtp-Source: ABdhPJwx1x3YtqAc2kZ071lfuuHzizqH/JXE+08HC3jE5fl+4Wzo3q7qJ75GNpu6NaL5MWTVtWf5Tw== X-Received: by 2002:a1c:f30e:: with SMTP id q14mr1359397wmq.87.1611091700798; Tue, 19 Jan 2021 13:28:20 -0800 (PST) Received: from localhost.localdomain ([212.86.35.161]) by smtp.gmail.com with ESMTPSA id r2sm39448819wrn.83.2021.01.19.13.28.19 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Tue, 19 Jan 2021 13:28:20 -0800 (PST) From: Rafael Silva To: git@vger.kernel.org Cc: Eric Sunshine , Phillip Wood , Rafael Silva Subject: [PATCH v3 6/7] worktree: teach `list` to annotate prunable worktree Date: Tue, 19 Jan 2021 22:27:38 +0100 Message-Id: <20210119212739.77882-7-rafaeloliveira.cs@gmail.com> X-Mailer: git-send-email 2.30.0.421.g32f838e276 In-Reply-To: <20210119212739.77882-1-rafaeloliveira.cs@gmail.com> References: <20210117234244.95106-1-rafaeloliveira.cs@gmail.com> <20210119212739.77882-1-rafaeloliveira.cs@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org The "git worktree list" command shows the absolute path to the worktree, the commit that is checked out, the name of the branch, and a "locked" annotation if the worktree is locked, however, it does not indicate whether the worktree is prunable. The "prune" command will remove a worktree if it is prunable unless `--dry-run` option is specified. This could lead to a worktree being removed without the user realizing before it is too late, in case the user forgets to pass --dry-run for instance. If the "list" command shows which worktree is prunable, the user could verify before running "git worktree prune" and hopefully prevents the working tree to be removed "accidentally" on the worse case scenario. Let's teach "git worktree list" to show when a worktree is a prunable candidate for both default and porcelain format. In the default format a "prunable" text is appended: $ git worktree list /path/to/main aba123 [main] /path/to/linked 123abc [branch-a] /path/to/prunable ace127 (detached HEAD) prunable In the --porcelain format a prunable label is added followed by its reason: $ git worktree list --porcelain ... worktree /path/to/prunable HEAD abc1234abc1234abc1234abc1234abc1234abc12 detached prunable gitdir file points to non-existent location ... Helped-by: Eric Sunshine Signed-off-by: Rafael Silva --- Documentation/git-worktree.txt | 26 ++++++++++++++++++++++++-- builtin/worktree.c | 10 ++++++++++ builtin/worktree.cc | 0 t/t2402-worktree-list.sh | 32 ++++++++++++++++++++++++++++++++ 4 files changed, 66 insertions(+), 2 deletions(-) create mode 100644 builtin/worktree.cc diff --git a/Documentation/git-worktree.txt b/Documentation/git-worktree.txt index 7cb8124f28..e0dd291e30 100644 --- a/Documentation/git-worktree.txt +++ b/Documentation/git-worktree.txt @@ -97,8 +97,9 @@ list:: List details of each working tree. The main working tree is listed first, followed by each of the linked working trees. The output details include whether the working tree is bare, the revision currently checked out, the -branch currently checked out (or "detached HEAD" if none), and "locked" if -the worktree is locked. +branch currently checked out (or "detached HEAD" if none), "locked" if +the worktree is locked, "prunable" if the worktree can be pruned by `prune` +command. lock:: @@ -234,6 +235,9 @@ This can also be set up as the default behaviour by using the --expire