From patchwork Wed Aug 11 04:57:21 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Felipe Contreras X-Patchwork-Id: 12430039 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.7 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,URIBL_BLOCKED,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 D222EC4320A for ; Wed, 11 Aug 2021 04:57:33 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id AE27A60EB9 for ; Wed, 11 Aug 2021 04:57:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234032AbhHKE5z (ORCPT ); Wed, 11 Aug 2021 00:57:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36798 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233873AbhHKE5y (ORCPT ); Wed, 11 Aug 2021 00:57:54 -0400 Received: from mail-oi1-x22b.google.com (mail-oi1-x22b.google.com [IPv6:2607:f8b0:4864:20::22b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5B7FDC061765 for ; Tue, 10 Aug 2021 21:57:31 -0700 (PDT) Received: by mail-oi1-x22b.google.com with SMTP id s13so2784328oie.10 for ; Tue, 10 Aug 2021 21:57:31 -0700 (PDT) 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=BKQXCP1g+/+Ob4egcu0oIyMr9O//ZOcWYi2mif1VNf8=; b=CWHJsCiVqS5M7njHNbHfu/a86qkIw4atFO49xutat5leiT/YePvFEWMLQ4lbaD2jgN 4ulYgTPqw88bKnJTsV2klEIkme8EhkoozWdBZ4IQs1rJf+XJZtQ5j9U02qE4TVYgzYEv klHEn1Dr19fs3NQ8Z4pad1bSjETbigUcQaqSUEodgxKMMRJFMeV25ju7oOYjRqa690vG ISPxIC4BL5zd7n+2tTutNaX4bpbldOynNqs7aAw0c++pUu5Wg7nZY5kK2u4+SxsuuQ+Z wdoM8n2M0gDje4J1DOT2qfhNhen+Pa1zNxbklx9NNwcbu8PUvWQjLJlz4wVVXRnM7y3A hErA== 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=BKQXCP1g+/+Ob4egcu0oIyMr9O//ZOcWYi2mif1VNf8=; b=PRIG7PjdwipVtFkk15A7o/AePqoN5koMENBXLRfo+NcKnas1I4/kOhXk1XClXefX2i ROZSTlO8Cr24tSIMY/yyHPwzuFm5xTafo0NjltGyM42REIrNLLfK/ucSozJdxjJdvsjp UGXuvTiTk3zKMHGUGShY7aUBKZOKCBXBidHrinrNoya4AOXunEtGlKsCHKkiw15aATVb wDsQImIg8JaWHsG5xgNc7b0lOF1HqdY+sdbMZG9G70IyEs8uY5mfmgATA5MwSBQPdiz8 Dx+MlF9nxEB7tHsyh7kEPIT1PqGhsyt8UcB2zx7JoxVwOLW7o8J4hTfthoWOX7/2hxJa CnmQ== X-Gm-Message-State: AOAM533XCCw1/u72G20BMm1Mt7etini/FgoWByEbhhDrzlTaal/j1zoC yJ0RKOVCkjREVmn2mz7vkZY7B7Zcut7qxQ== X-Google-Smtp-Source: ABdhPJxdkLc6KwjUMa3shu0qWzae1zlQ0IM9bhlWvBKxzNzDLhgeV4AgkQ8g5fuuBWmxdnh8CCO+Rg== X-Received: by 2002:aca:4ed6:: with SMTP id c205mr356841oib.57.1628657850521; Tue, 10 Aug 2021 21:57:30 -0700 (PDT) Received: from localhost (fixed-187-189-69-1.totalplay.net. [187.189.69.1]) by smtp.gmail.com with ESMTPSA id r15sm4180211otn.33.2021.08.10.21.57.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Aug 2021 21:57:30 -0700 (PDT) From: Felipe Contreras To: git@vger.kernel.org Cc: Jonathan Nieder , Matthieu Moy , Michael J Gruber , Felipe Contreras Subject: [PATCH 1/7] stage: add proper 'stage' command Date: Tue, 10 Aug 2021 23:57:21 -0500 Message-Id: <20210811045727.2381-2-felipe.contreras@gmail.com> X-Mailer: git-send-email 2.32.0.48.g096519100f In-Reply-To: <20210811045727.2381-1-felipe.contreras@gmail.com> References: <20210811045727.2381-1-felipe.contreras@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org This is still basically the same as `git add`, but now more easily extendable. Signed-off-by: Felipe Contreras --- Documentation/git-stage.txt | 11 ++++++++--- Makefile | 2 +- builtin.h | 1 + builtin/stage.c | 23 +++++++++++++++++++++++ git.c | 2 +- t/t3710-stage.sh | 20 ++++++++++++++++++++ 6 files changed, 54 insertions(+), 5 deletions(-) create mode 100644 builtin/stage.c create mode 100755 t/t3710-stage.sh diff --git a/Documentation/git-stage.txt b/Documentation/git-stage.txt index 25bcda936d..3f7b036901 100644 --- a/Documentation/git-stage.txt +++ b/Documentation/git-stage.txt @@ -9,14 +9,19 @@ git-stage - Add file contents to the staging area SYNOPSIS -------- [verse] -'git stage' args... +'git stage' [options] [--] [...] DESCRIPTION ----------- -This is a synonym for linkgit:git-add[1]. Please refer to the -documentation of that command. +The staging area is a location where changes are stored in preparation for a commit. + +This is a synonym for linkgit:git-add[1]. + +SEE ALSO +-------- +linkgit:git-add[1] GIT --- diff --git a/Makefile b/Makefile index c3565fc0f8..0223ed7cb1 100644 --- a/Makefile +++ b/Makefile @@ -779,7 +779,6 @@ BUILT_INS += git-maintenance$X BUILT_INS += git-merge-subtree$X BUILT_INS += git-restore$X BUILT_INS += git-show$X -BUILT_INS += git-stage$X BUILT_INS += git-status$X BUILT_INS += git-switch$X BUILT_INS += git-whatchanged$X @@ -1153,6 +1152,7 @@ BUILTIN_OBJS += builtin/show-branch.o BUILTIN_OBJS += builtin/show-index.o BUILTIN_OBJS += builtin/show-ref.o BUILTIN_OBJS += builtin/sparse-checkout.o +BUILTIN_OBJS += builtin/stage.o BUILTIN_OBJS += builtin/stash.o BUILTIN_OBJS += builtin/stripspace.o BUILTIN_OBJS += builtin/submodule--helper.o diff --git a/builtin.h b/builtin.h index 16ecd5586f..d08d803c4f 100644 --- a/builtin.h +++ b/builtin.h @@ -218,6 +218,7 @@ int cmd_show(int argc, const char **argv, const char *prefix); int cmd_show_branch(int argc, const char **argv, const char *prefix); int cmd_show_index(int argc, const char **argv, const char *prefix); int cmd_sparse_checkout(int argc, const char **argv, const char *prefix); +int cmd_stage(int argc, const char **argv, const char *prefix); int cmd_status(int argc, const char **argv, const char *prefix); int cmd_stash(int argc, const char **argv, const char *prefix); int cmd_stripspace(int argc, const char **argv, const char *prefix); diff --git a/builtin/stage.c b/builtin/stage.c new file mode 100644 index 0000000000..4dcefbedba --- /dev/null +++ b/builtin/stage.c @@ -0,0 +1,23 @@ +/* + * Copyright (C) 2013-2021 Felipe Contreras + */ + +#include "builtin.h" +#include "parse-options.h" + +static const char *const stage_usage[] = { + N_("git stage [options] [--] ..."), + NULL +}; + +int cmd_stage(int argc, const char **argv, const char *prefix) +{ + struct option options[] = { + OPT_END() + }; + + argc = parse_options(argc, argv, prefix, options, stage_usage, + PARSE_OPT_KEEP_ARGV0 | PARSE_OPT_KEEP_UNKNOWN | PARSE_OPT_KEEP_DASHDASH); + + return cmd_add(argc, argv, prefix); +} diff --git a/git.c b/git.c index 18bed9a996..3b92e60329 100644 --- a/git.c +++ b/git.c @@ -599,7 +599,7 @@ static struct cmd_struct commands[] = { { "show-index", cmd_show_index, RUN_SETUP_GENTLY }, { "show-ref", cmd_show_ref, RUN_SETUP }, { "sparse-checkout", cmd_sparse_checkout, RUN_SETUP | NEED_WORK_TREE }, - { "stage", cmd_add, RUN_SETUP | NEED_WORK_TREE }, + { "stage", cmd_stage, RUN_SETUP | NEED_WORK_TREE }, { "stash", cmd_stash, RUN_SETUP | NEED_WORK_TREE }, { "status", cmd_status, RUN_SETUP | NEED_WORK_TREE }, { "stripspace", cmd_stripspace }, diff --git a/t/t3710-stage.sh b/t/t3710-stage.sh new file mode 100755 index 0000000000..2bf59905ca --- /dev/null +++ b/t/t3710-stage.sh @@ -0,0 +1,20 @@ +#!/bin/sh +# +# Copyright (C) 2021 Felipe Contreras +# + +test_description='Tests of git stage' + +. ./test-lib.sh + +in_stage () { + test "$(git ls-files "$1")" == "$1" +} + +test_expect_success 'basic' ' + touch foo && + git stage foo && + in_stage foo +' + +test_done From patchwork Wed Aug 11 04:57:22 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Felipe Contreras X-Patchwork-Id: 12430043 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 25011C4338F for ; Wed, 11 Aug 2021 04:57:39 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id F402660EB9 for ; Wed, 11 Aug 2021 04:57:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234065AbhHKE6A (ORCPT ); Wed, 11 Aug 2021 00:58:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36808 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233873AbhHKE54 (ORCPT ); Wed, 11 Aug 2021 00:57:56 -0400 Received: from mail-oi1-x22e.google.com (mail-oi1-x22e.google.com [IPv6:2607:f8b0:4864:20::22e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6F724C061765 for ; Tue, 10 Aug 2021 21:57:33 -0700 (PDT) Received: by mail-oi1-x22e.google.com with SMTP id s13so2784403oie.10 for ; Tue, 10 Aug 2021 21:57:33 -0700 (PDT) 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=FCi92CAeZOSxGpt5h3IyvgXcT9W7iC2wsJV8iYq4IFI=; b=REzagwzoxvJSzRZTWreaSvcEWP1wzL7m36sOFg3xtwm5B+pOaL6PTzdK+XcavV2ZDF pEUa2JF3bLonv86n+Ldw7eNAFwG36m88zHchOEI3zdJzUtT7MaXs2jhSNQ0iziosncwx +ejObH/9P7yRSi5P8q2S8wc8aHPq0MaQMuRUi+8QKrdU8pqG1SqjjBzukVH9Jom86zI6 X1J3h9iSgGV8AQw5YZ1A/D03txCKjH6jGwwkdqz/gKVkkGJLbOP7nzmNHvAWiJ+GtFo8 jf1kGDtBu8R+D5aRarfUHbw+XNHtPmVfFKZ6fVZMJ1ybsQ3hz6+qr2SzNsg3jsUejxH/ ANeA== 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=FCi92CAeZOSxGpt5h3IyvgXcT9W7iC2wsJV8iYq4IFI=; b=GOxTBTaIqWFGaHYsJY8O39/AwZDVSubFPlNXqX/OhOVNJBIRBGPlaZTntsixIWRidE VnPD71p6FIJUvUkCPpUJsZ48KDdVoM+h33GLETVDdVVZ4Vjsp4a1VKgFE5+eR1aPGgse lPrDxTGoPaz21BYtvQKa2JJ6QSQChqxHpsIU73Rhqc49vFDvPXLatPDbwHTJCtL+Oo9i V6UjGgdL/RziDGqr6yr12I0U7e+6pc/Sy2mvISx4kzTRltQDdt0gNEuH4OxwYG5kFzmX fL2g37TbxOYtjxHhBolBgNuMP8fk4713HLxGAZfMxhHn/fHQm7+XIXLz6nPk3jWcoaR3 ZKZg== X-Gm-Message-State: AOAM533x42o+BZPE8Kr6DOSu5FgLGd8zGy8R/GsyH+LveIkovsEa8x1Q VqTxWVBzHHuGxRivOchtFRCUhRv/V2gmaw== X-Google-Smtp-Source: ABdhPJwiRH4BBZvVQoRSfyLh8YBwGp+GiZgwOz6UJtZYtP6xG+ltBcuvezbsI3XFVd6CulDgY9lFWQ== X-Received: by 2002:a05:6808:7cb:: with SMTP id f11mr10249588oij.56.1628657852415; Tue, 10 Aug 2021 21:57:32 -0700 (PDT) Received: from localhost (fixed-187-189-69-1.totalplay.net. [187.189.69.1]) by smtp.gmail.com with ESMTPSA id r1sm3734383ooi.21.2021.08.10.21.57.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Aug 2021 21:57:31 -0700 (PDT) From: Felipe Contreras To: git@vger.kernel.org Cc: Jonathan Nieder , Matthieu Moy , Michael J Gruber , Felipe Contreras Subject: [PATCH 2/7] stage: add helper to run commands Date: Tue, 10 Aug 2021 23:57:22 -0500 Message-Id: <20210811045727.2381-3-felipe.contreras@gmail.com> X-Mailer: git-send-email 2.32.0.48.g096519100f In-Reply-To: <20210811045727.2381-1-felipe.contreras@gmail.com> References: <20210811045727.2381-1-felipe.contreras@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Will be useful to run other commands. Signed-off-by: Felipe Contreras --- builtin/stage.c | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/builtin/stage.c b/builtin/stage.c index 4dcefbedba..49016b0d5f 100644 --- a/builtin/stage.c +++ b/builtin/stage.c @@ -4,12 +4,34 @@ #include "builtin.h" #include "parse-options.h" +#include "run-command.h" static const char *const stage_usage[] = { N_("git stage [options] [--] ..."), NULL }; +static int rerun(int argc, const char **argv, ...) +{ + int ret; + struct strvec args = STRVEC_INIT; + va_list ap; + const char *arg; + int i; + + va_start(ap, argv); + while ((arg = va_arg(ap, const char *))) + strvec_push(&args, arg); + va_end(ap); + + for (i = 0; i < argc; i++) + strvec_push(&args, argv[i]); + + ret = run_command_v_opt(args.v, RUN_GIT_CMD); + strvec_clear(&args); + return ret; +} + int cmd_stage(int argc, const char **argv, const char *prefix) { struct option options[] = { @@ -17,7 +39,7 @@ int cmd_stage(int argc, const char **argv, const char *prefix) }; argc = parse_options(argc, argv, prefix, options, stage_usage, - PARSE_OPT_KEEP_ARGV0 | PARSE_OPT_KEEP_UNKNOWN | PARSE_OPT_KEEP_DASHDASH); + PARSE_OPT_KEEP_UNKNOWN | PARSE_OPT_KEEP_DASHDASH); - return cmd_add(argc, argv, prefix); + return rerun(argc, argv, "add", NULL); } From patchwork Wed Aug 11 04:57:23 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Felipe Contreras X-Patchwork-Id: 12430045 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.7 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,URIBL_BLOCKED,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 4CF4CC4320A for ; Wed, 11 Aug 2021 04:57:39 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 307A960EB9 for ; Wed, 11 Aug 2021 04:57:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234109AbhHKE6B (ORCPT ); Wed, 11 Aug 2021 00:58:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36822 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234105AbhHKE56 (ORCPT ); Wed, 11 Aug 2021 00:57:58 -0400 Received: from mail-ot1-x330.google.com (mail-ot1-x330.google.com [IPv6:2607:f8b0:4864:20::330]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 033E4C061799 for ; Tue, 10 Aug 2021 21:57:35 -0700 (PDT) Received: by mail-ot1-x330.google.com with SMTP id 108-20020a9d01750000b029050e5cc11ae3so1959859otu.5 for ; Tue, 10 Aug 2021 21:57:34 -0700 (PDT) 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=wRc80Wly3gkGEC9v0m5UQMTUEmsXTxaF8hBoUEHlKv0=; b=kco9555504aYS+wKG6jSNK/+KvwmdmdwGMOT7CCqUBOMGsDYJqk52Huwy5bxOprnNs ZiT/A+GFKWQU49a9cOZ9kHyw/hCOV4awbPGLbNKOdIPZFIvuHbmVOHWjFABy8eSm4r8w LbzURHnL92rd1HKTAIt6OmuGtdLG4PHtInYV7tDSuk1LqoEeyeCoWeP3+uKDSU1YuRcV PrdYKVd/P6hPZJ9bHY5thtvoE7aShaGcSkEDJGAZYzk5fMq7yg31aRZY2SAdDn7tIhMq knq1K/xlA4lnnGtv09atWHvPSYBEWZJ4euc/wVOjU7VQsaOj5fYnNOQ24YmjUCHmLx9g o5Sw== 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=wRc80Wly3gkGEC9v0m5UQMTUEmsXTxaF8hBoUEHlKv0=; b=VuNYa7EA0JbpUAqhRdAUYJmAFGH5jtYLMg+YoQLOsBtRbHDyAPvwHLUHG+Vm7er5F0 bUy26MpQin/dvte75JCbVzt2H0jHCzJ+85o7QSDm7EAwHAVK/OKaKjfW6zf7k5YCAbs9 4Xi71MjsMkkV3yp6v/dzv5/ta6xAuO4Ps3AoBLFTVQ1Nq4SFaxSGliqh8bc2sOIabi5x BCTCNFEnY2EsQDImOEn3YXg4ZaUPR/s5ovO5y0kEom7n9urI7MJ9/XkMp0lUWUTnelwl OsxMOcZ9v2v3hrZb3jUYhpcQQ+2uuSXBnXW8s7EINg7wsqJfC8CHt6Tbs7CVvHcHA0kc iTxA== X-Gm-Message-State: AOAM530YRuZs95pIYssDLd+6vlygOm8QEI4Zw6RikXAkTX8jEVwBVwJN doXX/wyFkrcfMHc69Srnv2wh24sQP7AOqQ== X-Google-Smtp-Source: ABdhPJxJozaO9P96PXPm+e3iwZxdMwOj6Cjzwf6FB38LWYeODbJNWpncJ8C4LysdUiQK4EiskFyyMQ== X-Received: by 2002:a05:6830:151:: with SMTP id j17mr10767480otp.327.1628657854102; Tue, 10 Aug 2021 21:57:34 -0700 (PDT) Received: from localhost (fixed-187-189-69-1.totalplay.net. [187.189.69.1]) by smtp.gmail.com with ESMTPSA id j18sm291555ots.10.2021.08.10.21.57.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Aug 2021 21:57:33 -0700 (PDT) From: Felipe Contreras To: git@vger.kernel.org Cc: Jonathan Nieder , Matthieu Moy , Michael J Gruber , Felipe Contreras Subject: [PATCH 3/7] stage: add 'add' subcommand Date: Tue, 10 Aug 2021 23:57:23 -0500 Message-Id: <20210811045727.2381-4-felipe.contreras@gmail.com> X-Mailer: git-send-email 2.32.0.48.g096519100f In-Reply-To: <20210811045727.2381-1-felipe.contreras@gmail.com> References: <20210811045727.2381-1-felipe.contreras@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Signed-off-by: Felipe Contreras --- Documentation/git-stage.txt | 15 ++++++++++++--- builtin/stage.c | 4 ++++ contrib/completion/git-completion.bash | 5 +++++ t/t3710-stage.sh | 6 ++++++ 4 files changed, 27 insertions(+), 3 deletions(-) diff --git a/Documentation/git-stage.txt b/Documentation/git-stage.txt index 3f7b036901..348d7d1d92 100644 --- a/Documentation/git-stage.txt +++ b/Documentation/git-stage.txt @@ -3,21 +3,30 @@ git-stage(1) NAME ---- -git-stage - Add file contents to the staging area +git-stage - Manage the staging area SYNOPSIS -------- [verse] 'git stage' [options] [--] [...] +'git stage' (-a | --add) [options] [--] [...] DESCRIPTION ----------- -The staging area is a location where changes are stored in preparation for a commit. +This command is useful to manage the staging area which is a location where +changes are stored in preparation for a commit. + +Without arguments it's a synonym for linkgit:git-add[1]. + +OPTIONS +------- +-a:: +--add:: + Add changes to the staging area. See linkgit:git-add[1]. -This is a synonym for linkgit:git-add[1]. SEE ALSO -------- diff --git a/builtin/stage.c b/builtin/stage.c index 49016b0d5f..5a80bbc76c 100644 --- a/builtin/stage.c +++ b/builtin/stage.c @@ -8,6 +8,7 @@ static const char *const stage_usage[] = { N_("git stage [options] [--] ..."), + N_("git stage --add [options] [--] ..."), NULL }; @@ -34,7 +35,10 @@ static int rerun(int argc, const char **argv, ...) int cmd_stage(int argc, const char **argv, const char *prefix) { + int add = 0; + struct option options[] = { + OPT_BOOL_F('a', "add", &add, N_("add changes"), PARSE_OPT_NONEG), OPT_END() }; diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash index b50c5d0ea3..8656c47f39 100644 --- a/contrib/completion/git-completion.bash +++ b/contrib/completion/git-completion.bash @@ -2376,6 +2376,11 @@ _git_send_email () _git_stage () { + if [[ "$cur" == --* ]]; then + __gitcomp_builtin stage + return + fi + _git_add } diff --git a/t/t3710-stage.sh b/t/t3710-stage.sh index 2bf59905ca..225c6dd739 100755 --- a/t/t3710-stage.sh +++ b/t/t3710-stage.sh @@ -17,4 +17,10 @@ test_expect_success 'basic' ' in_stage foo ' +test_expect_success 'add' ' + touch bar && + git stage --add bar && + in_stage bar +' + test_done From patchwork Wed Aug 11 04:57:24 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Felipe Contreras X-Patchwork-Id: 12430047 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.7 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,URIBL_BLOCKED,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 C6C52C4338F for ; Wed, 11 Aug 2021 04:57:41 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A783660C40 for ; Wed, 11 Aug 2021 04:57:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234117AbhHKE6C (ORCPT ); Wed, 11 Aug 2021 00:58:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36838 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234086AbhHKE6A (ORCPT ); Wed, 11 Aug 2021 00:58:00 -0400 Received: from mail-oi1-x232.google.com (mail-oi1-x232.google.com [IPv6:2607:f8b0:4864:20::232]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8650FC06179F for ; Tue, 10 Aug 2021 21:57:36 -0700 (PDT) Received: by mail-oi1-x232.google.com with SMTP id bi32so2861663oib.2 for ; Tue, 10 Aug 2021 21:57:36 -0700 (PDT) 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=B7iZSzhX0298EA5UulCQR1FlJGT4jgu+42RRYbjB3Lg=; b=UyU0Do0qRWlbCVndGN5Tyh2DUZgtSXdvESGjxd8fXypwTo5/Jk4p7iksUxe3GwcyxS A+JO5rACmq2c5yJ0axqeDnLEoWrQfZpKn6a6C9GemjZiRZD43ulGJTiBU9Xzm0hjilCy +lDEhJWw4LmreZG1xaCEOJgWOFHcB6xz1M6nr59I0eMHdqsP44HMLpOxCu5uf3R2qieN uMLZI21lo0g+KrEpoEJV6KetMb9gCFaO6mE0mTLvYxdeIzpVXyOTEf+5r+HJ3xgBwjGS dLybgV9Nl1aKFDOmroBnxuIOgrVanUXm4sgWuE+2h0yBGquh90u+maKvqOiGs1f95y83 QUEg== 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=B7iZSzhX0298EA5UulCQR1FlJGT4jgu+42RRYbjB3Lg=; b=LW+xfukFWgxiqoqPS38V/e8pTBifLyv20R6ClP2iJXf/PbKuMnH1wdUxv+mCfnFHSO VhsdO2uHo8zWK25erkdVDCENqwiG7ZeBFQrD6mWPlxwFk2ilW9kqh4d+jlHiBpwb89D8 wDEp97Dx63rfkL5GMdt4rAYzcyfNiioB1cM5NNiCk/m30Stw2nWx3/yJckdfIUUR6+qp qOlVCOq85VVs0MwdYeoGL/+QleMF90LVLhpktveojcmhWGS79uWLfDzf/xx7BZ9ooy+W xRav29oDE4MAAup06+tbUJsDOH5rYkTZeZISgC1fi8HVtUbkNLyxjS6wc2Pp2mpZK3lU dFrw== X-Gm-Message-State: AOAM533hXlS0al1h4gPt6hQwTFSwhxt4xHGBn43V6Hk/ZDRcrM8tIs/+ PKyuE/G0e/QVrU9mIhf+rX2g2D/BeXPS4g== X-Google-Smtp-Source: ABdhPJz8fVzsBf74ERD8nPf0rDZHvBilXTSJm3n0q6sHrUfqmYUmgzNF3HiS20Rv/zrEj5jh8HdZrA== X-Received: by 2002:a05:6808:1807:: with SMTP id bh7mr6099483oib.52.1628657855666; Tue, 10 Aug 2021 21:57:35 -0700 (PDT) Received: from localhost (fixed-187-189-69-1.totalplay.net. [187.189.69.1]) by smtp.gmail.com with ESMTPSA id p2sm4456622oip.35.2021.08.10.21.57.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Aug 2021 21:57:35 -0700 (PDT) From: Felipe Contreras To: git@vger.kernel.org Cc: Jonathan Nieder , Matthieu Moy , Michael J Gruber , Felipe Contreras Subject: [PATCH 4/7] stage: add 'remove' subcommand Date: Tue, 10 Aug 2021 23:57:24 -0500 Message-Id: <20210811045727.2381-5-felipe.contreras@gmail.com> X-Mailer: git-send-email 2.32.0.48.g096519100f In-Reply-To: <20210811045727.2381-1-felipe.contreras@gmail.com> References: <20210811045727.2381-1-felipe.contreras@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Signed-off-by: Felipe Contreras --- Documentation/git-stage.txt | 6 ++++++ builtin/stage.c | 7 ++++++- t/t3710-stage.sh | 5 +++++ 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/Documentation/git-stage.txt b/Documentation/git-stage.txt index 348d7d1d92..e2f83783b2 100644 --- a/Documentation/git-stage.txt +++ b/Documentation/git-stage.txt @@ -11,6 +11,7 @@ SYNOPSIS [verse] 'git stage' [options] [--] [...] 'git stage' (-a | --add) [options] [--] [...] +'git stage' (-r | --remove) [options] [--] [...] DESCRIPTION @@ -27,10 +28,15 @@ OPTIONS --add:: Add changes to the staging area. See linkgit:git-add[1]. +-r:: +--remove:: + Remove changes from the staging area. See linkgit:git-reset[1]. + SEE ALSO -------- linkgit:git-add[1] +linkgit:git-reset[1] GIT --- diff --git a/builtin/stage.c b/builtin/stage.c index 5a80bbc76c..dee8781dc5 100644 --- a/builtin/stage.c +++ b/builtin/stage.c @@ -9,6 +9,7 @@ static const char *const stage_usage[] = { N_("git stage [options] [--] ..."), N_("git stage --add [options] [--] ..."), + N_("git stage --remove [options] [--] ..."), NULL }; @@ -35,15 +36,19 @@ static int rerun(int argc, const char **argv, ...) int cmd_stage(int argc, const char **argv, const char *prefix) { - int add = 0; + int add = 0, remove = 0; struct option options[] = { OPT_BOOL_F('a', "add", &add, N_("add changes"), PARSE_OPT_NONEG), + OPT_BOOL_F('r', "remove", &remove, N_("remove changes"), PARSE_OPT_NONEG), OPT_END() }; argc = parse_options(argc, argv, prefix, options, stage_usage, PARSE_OPT_KEEP_UNKNOWN | PARSE_OPT_KEEP_DASHDASH); + if (remove) + return rerun(argc, argv, "reset", NULL); + return rerun(argc, argv, "add", NULL); } diff --git a/t/t3710-stage.sh b/t/t3710-stage.sh index 225c6dd739..209f2bde9a 100755 --- a/t/t3710-stage.sh +++ b/t/t3710-stage.sh @@ -23,4 +23,9 @@ test_expect_success 'add' ' in_stage bar ' +test_expect_success 'remove' ' + git stage --remove bar && + ! in_stage bar +' + test_done From patchwork Wed Aug 11 04:57:25 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Felipe Contreras X-Patchwork-Id: 12430049 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.7 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,URIBL_BLOCKED,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 20A09C4338F for ; Wed, 11 Aug 2021 04:57:44 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 01D4060C40 for ; Wed, 11 Aug 2021 04:57:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234243AbhHKE6G (ORCPT ); Wed, 11 Aug 2021 00:58:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36844 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234115AbhHKE6B (ORCPT ); Wed, 11 Aug 2021 00:58:01 -0400 Received: from mail-oi1-x233.google.com (mail-oi1-x233.google.com [IPv6:2607:f8b0:4864:20::233]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 26D10C061765 for ; Tue, 10 Aug 2021 21:57:38 -0700 (PDT) Received: by mail-oi1-x233.google.com with SMTP id h11so2912493oie.0 for ; Tue, 10 Aug 2021 21:57:38 -0700 (PDT) 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=9RxztbMBSydknvjo9KVqjccctAKEHcBiI11pEBFR2m4=; b=IftnNJ7YIN/k8KwR7BHcZFFR76Ul6sOWDbC5ECxSMFhCM4JmmygThQZxFwWcA402dk 75xSUaLJ/xozofUAhlPs/capGTKJTCXrnfyChn/O1rrJPqsuKds+YBbBWws5OrUWFmLz TsG5N/t9LqEjSY9iWmuJAAPuGLf6PGxJmWM2HyGZQVxzNNt6ucL1HaO1fWt9QAPESsS+ Fnq+4bIdBo25HDYQ8DHzeWWR7r7gclDyXYhzrB4HBAaV6AWNR8edLcxhhZ4D1jj7oK3s 27cv687syr/ppV4m99JJwsllzW3zq8Y8LredwTO9pPUKlBehWYnIgliiweoSmCHMS1T5 CO2g== 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=9RxztbMBSydknvjo9KVqjccctAKEHcBiI11pEBFR2m4=; b=b1IWFDmFuTfumBa7f4cBRUGfzLbvUJr+Flp8/ACIEUJIm+8JwGwXltYD0LkAzEh+U8 vGq6+xJRWtNVB4g/ZGr0pKtTU48B3I8TS2xEpjetLSY9N/M5ohOr8/F2vapfiyyCoZOV XnUxZ1BPfruUthsaBHp8qGTaYoyffsolvd/CwJ0wd4G5bHKpqN8xEgrNYZhDX8YWSA9b zE5foVQ1tUDpT6ZtGzvM+IgRRp4f7oLwMlW/YZPwxMsBGIr9JL157qgb/gEyHZMS3a4z +R0HZDsGBzX95rixzDRyz5d6A+qE36tPT32HVS0ZEfs3bkZdhtiY/Gl0NQIah4MChhIl LIFQ== X-Gm-Message-State: AOAM531/j1hYCPoQg9s1+SJvWC+SK8hQvwoXLnX8fNRC1zlYsvSNpxfe ceyjnlUt4yiK1N7J6wF9hoSIqjZIKblY+A== X-Google-Smtp-Source: ABdhPJzIZCZkgbXRnEMbzhGQAPjVF2W1pOgusa8YMkIem/szJBBScIt3IoiSHwgrs/Xm6HFQ+4J+tA== X-Received: by 2002:aca:2403:: with SMTP id n3mr8970637oic.109.1628657857246; Tue, 10 Aug 2021 21:57:37 -0700 (PDT) Received: from localhost (fixed-187-189-69-1.totalplay.net. [187.189.69.1]) by smtp.gmail.com with ESMTPSA id n9sm4292281otn.54.2021.08.10.21.57.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Aug 2021 21:57:36 -0700 (PDT) From: Felipe Contreras To: git@vger.kernel.org Cc: Jonathan Nieder , Matthieu Moy , Michael J Gruber , Felipe Contreras Subject: [PATCH 5/7] unstage: add 'unstage' command Date: Tue, 10 Aug 2021 23:57:25 -0500 Message-Id: <20210811045727.2381-6-felipe.contreras@gmail.com> X-Mailer: git-send-email 2.32.0.48.g096519100f In-Reply-To: <20210811045727.2381-1-felipe.contreras@gmail.com> References: <20210811045727.2381-1-felipe.contreras@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Signed-off-by: Felipe Contreras --- Documentation/git-unstage.txt | 25 +++++++++++++++++++++++++ builtin.h | 1 + builtin/stage.c | 15 +++++++++++++++ git.c | 1 + t/t3710-stage.sh | 7 +++++++ 5 files changed, 49 insertions(+) create mode 100644 Documentation/git-unstage.txt diff --git a/Documentation/git-unstage.txt b/Documentation/git-unstage.txt new file mode 100644 index 0000000000..cafc24cb36 --- /dev/null +++ b/Documentation/git-unstage.txt @@ -0,0 +1,25 @@ +git-unstage(1) +============== + +NAME +---- +git-unstage - Remove changes from the staging area + + +SYNOPSIS +-------- +[verse] +'git unstage' [options] [--] [...] + +DESCRIPTION +----------- + +Removes changes from the staging area. This is the same as `git reset`. + +SEE ALSO +-------- +linkgit:git-reset[1] + +GIT +--- +Part of the linkgit:git[1] suite diff --git a/builtin.h b/builtin.h index d08d803c4f..326f8af3e7 100644 --- a/builtin.h +++ b/builtin.h @@ -229,6 +229,7 @@ int cmd_tag(int argc, const char **argv, const char *prefix); int cmd_tar_tree(int argc, const char **argv, const char *prefix); int cmd_unpack_file(int argc, const char **argv, const char *prefix); int cmd_unpack_objects(int argc, const char **argv, const char *prefix); +int cmd_unstage(int argc, const char **argv, const char *prefix); int cmd_update_index(int argc, const char **argv, const char *prefix); int cmd_update_ref(int argc, const char **argv, const char *prefix); int cmd_update_server_info(int argc, const char **argv, const char *prefix); diff --git a/builtin/stage.c b/builtin/stage.c index dee8781dc5..2d50b3c393 100644 --- a/builtin/stage.c +++ b/builtin/stage.c @@ -13,6 +13,11 @@ static const char *const stage_usage[] = { NULL }; +static const char *const unstage_usage[] = { + N_("git unstage [options] [--] ..."), + NULL +}; + static int rerun(int argc, const char **argv, ...) { int ret; @@ -52,3 +57,13 @@ int cmd_stage(int argc, const char **argv, const char *prefix) return rerun(argc, argv, "add", NULL); } + +int cmd_unstage(int argc, const char **argv, const char *prefix) +{ + struct option options[] = { OPT_END() }; + + argc = parse_options(argc, argv, prefix, options, unstage_usage, + PARSE_OPT_KEEP_UNKNOWN | PARSE_OPT_KEEP_DASHDASH); + + return rerun(argc, argv, "reset", NULL); +} diff --git a/git.c b/git.c index 3b92e60329..2d319cc15b 100644 --- a/git.c +++ b/git.c @@ -607,6 +607,7 @@ static struct cmd_struct commands[] = { { "switch", cmd_switch, RUN_SETUP | NEED_WORK_TREE }, { "symbolic-ref", cmd_symbolic_ref, RUN_SETUP }, { "tag", cmd_tag, RUN_SETUP | DELAY_PAGER_CONFIG }, + { "unstage", cmd_unstage, RUN_SETUP | NEED_WORK_TREE }, { "unpack-file", cmd_unpack_file, RUN_SETUP | NO_PARSEOPT }, { "unpack-objects", cmd_unpack_objects, RUN_SETUP | NO_PARSEOPT }, { "update-index", cmd_update_index, RUN_SETUP }, diff --git a/t/t3710-stage.sh b/t/t3710-stage.sh index 209f2bde9a..834eee66d5 100755 --- a/t/t3710-stage.sh +++ b/t/t3710-stage.sh @@ -28,4 +28,11 @@ test_expect_success 'remove' ' ! in_stage bar ' +test_expect_success 'unstage' ' + touch bar && + git stage bar && + git unstage bar && + ! in_stage bar +' + test_done From patchwork Wed Aug 11 04:57:26 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Felipe Contreras X-Patchwork-Id: 12430051 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.7 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,URIBL_BLOCKED,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 D793EC432BE for ; Wed, 11 Aug 2021 04:57:45 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id BD3F260C40 for ; Wed, 11 Aug 2021 04:57:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234136AbhHKE6H (ORCPT ); Wed, 11 Aug 2021 00:58:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36858 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234112AbhHKE6D (ORCPT ); Wed, 11 Aug 2021 00:58:03 -0400 Received: from mail-oi1-x22f.google.com (mail-oi1-x22f.google.com [IPv6:2607:f8b0:4864:20::22f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E2AAFC061798 for ; Tue, 10 Aug 2021 21:57:39 -0700 (PDT) Received: by mail-oi1-x22f.google.com with SMTP id t128so2858794oig.1 for ; Tue, 10 Aug 2021 21:57:39 -0700 (PDT) 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=/4+gcVRn0cHI+p6n/RurUG5QxeJqTeD6wcp6ayJQbRQ=; b=Zm0gjvCGhWO4Bu0KiEGMUIJzRpIToGEgyhC78U7TMaD2QuQOdVDGmBaYvW+TzUGzus MfGT83w2BhZcxETiBpUABq7ch1N0wGc4kECgcc7l8lQ/gGvbdB7A/5O/X0QMsnPvuqzN eeReahsnPIAomWk4ufDTeEtszLb+QwEkChaYdJyK1UWwzTmDTj3YrlDXHV3ataiudM6E eJMf6+zzVCb3bI7bD2BZkn6UwyEYK/OHrgICPSAIScVydZT8TQvGkpkuQDOYWWuH576o QPhdTbYTizkmYBcUeizRYFv4quhS9xo8gSO/vsowQSPahPpjfW68Nx6/81DiUUrgjcy4 Ja1w== 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=/4+gcVRn0cHI+p6n/RurUG5QxeJqTeD6wcp6ayJQbRQ=; b=EG8lFk2mompT3oRInXaTv7yidZoP63d+ojP4ylNwp1zEm9xsXuusrMQbPZiz884HkK 7ulXzqhr4Sgm7oOFInqjBIRtzXknJI649XHPnd+BGIIKz3C8Ad+0m0fbOotXPn/a6caV KzuIaFte7K5wGmi8bNYOqkejO3j4abNqTWo2Q4gMiThsTV0I7T9h7aEEMaPjwr0s09kK y75HRcITE/HJcaDyGiOWeyLBshuqsLaZKFoY3THinRCOVFKj+i7lvDsjUpdomv+ZTGOg usAeM2p9fdtqszFsUX4BOHIOFgRyXkCYU6VzF+uvdqxWoIh60DKW81+xz2nVq8QY3uql 59gw== X-Gm-Message-State: AOAM532rEYOl4us4Gai4HgKgBvq3q3Ri8Dcob4x7Rq76Vktt4DMvfYsG NhuUZ8J0pNri/iwFDP92IPOMDL2o9hvalQ== X-Google-Smtp-Source: ABdhPJwUaWqObfkONxiP9yeg6AgbH2zHtjbhdylqgyMfLXp3pIbYvnrr/wg9fz+6TUfJRms5AwRM2w== X-Received: by 2002:aca:ac51:: with SMTP id v78mr357172oie.96.1628657859060; Tue, 10 Aug 2021 21:57:39 -0700 (PDT) Received: from localhost (fixed-187-189-69-1.totalplay.net. [187.189.69.1]) by smtp.gmail.com with ESMTPSA id y138sm3662158oie.22.2021.08.10.21.57.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Aug 2021 21:57:38 -0700 (PDT) From: Felipe Contreras To: git@vger.kernel.org Cc: Jonathan Nieder , Matthieu Moy , Michael J Gruber , Felipe Contreras Subject: [PATCH 6/7] stage: add 'diff' subcommand Date: Tue, 10 Aug 2021 23:57:26 -0500 Message-Id: <20210811045727.2381-7-felipe.contreras@gmail.com> X-Mailer: git-send-email 2.32.0.48.g096519100f In-Reply-To: <20210811045727.2381-1-felipe.contreras@gmail.com> References: <20210811045727.2381-1-felipe.contreras@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Signed-off-by: Felipe Contreras --- Documentation/git-stage.txt | 5 +++++ builtin/stage.c | 6 +++++- t/t3710-stage.sh | 7 +++++++ 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/Documentation/git-stage.txt b/Documentation/git-stage.txt index e2f83783b2..460a8d6228 100644 --- a/Documentation/git-stage.txt +++ b/Documentation/git-stage.txt @@ -12,6 +12,7 @@ SYNOPSIS 'git stage' [options] [--] [...] 'git stage' (-a | --add) [options] [--] [...] 'git stage' (-r | --remove) [options] [--] [...] +'git stage' (-d | --diff) [options] [--] [...] DESCRIPTION @@ -32,11 +33,15 @@ OPTIONS --remove:: Remove changes from the staging area. See linkgit:git-reset[1]. +-d:: +--diff:: + View the changes staged for the next commit. See linkgit:git-diff[1]. SEE ALSO -------- linkgit:git-add[1] linkgit:git-reset[1] +linkgit:git-diff[1] GIT --- diff --git a/builtin/stage.c b/builtin/stage.c index 2d50b3c393..c57bb2d683 100644 --- a/builtin/stage.c +++ b/builtin/stage.c @@ -10,6 +10,7 @@ static const char *const stage_usage[] = { N_("git stage [options] [--] ..."), N_("git stage --add [options] [--] ..."), N_("git stage --remove [options] [--] ..."), + N_("git stage --diff [options] [] [--] ..."), NULL }; @@ -41,11 +42,12 @@ static int rerun(int argc, const char **argv, ...) int cmd_stage(int argc, const char **argv, const char *prefix) { - int add = 0, remove = 0; + int add = 0, remove = 0, diff = 0; struct option options[] = { OPT_BOOL_F('a', "add", &add, N_("add changes"), PARSE_OPT_NONEG), OPT_BOOL_F('r', "remove", &remove, N_("remove changes"), PARSE_OPT_NONEG), + OPT_BOOL_F('d', "diff", &diff, N_("show changes"), PARSE_OPT_NONEG), OPT_END() }; @@ -54,6 +56,8 @@ int cmd_stage(int argc, const char **argv, const char *prefix) if (remove) return rerun(argc, argv, "reset", NULL); + if (diff) + return rerun(argc, argv, "diff", "--staged", NULL); return rerun(argc, argv, "add", NULL); } diff --git a/t/t3710-stage.sh b/t/t3710-stage.sh index 834eee66d5..aab979c20c 100755 --- a/t/t3710-stage.sh +++ b/t/t3710-stage.sh @@ -35,4 +35,11 @@ test_expect_success 'unstage' ' ! in_stage bar ' +test_expect_success 'diff' ' + echo foo > foo && + git stage --add foo && + git stage --diff > out && + test_file_not_empty out +' + test_done From patchwork Wed Aug 11 04:57:27 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Felipe Contreras X-Patchwork-Id: 12430053 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.7 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,URIBL_BLOCKED,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 DDD40C4338F for ; Wed, 11 Aug 2021 04:57:47 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id C034A60C40 for ; Wed, 11 Aug 2021 04:57:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234253AbhHKE6J (ORCPT ); Wed, 11 Aug 2021 00:58:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36858 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234246AbhHKE6G (ORCPT ); Wed, 11 Aug 2021 00:58:06 -0400 Received: from mail-ot1-x336.google.com (mail-ot1-x336.google.com [IPv6:2607:f8b0:4864:20::336]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B575BC06179E for ; Tue, 10 Aug 2021 21:57:41 -0700 (PDT) Received: by mail-ot1-x336.google.com with SMTP id c23-20020a0568301af7b029050cd611fb72so1970365otd.3 for ; Tue, 10 Aug 2021 21:57:41 -0700 (PDT) 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=YyOgyO63SOQpzUzoJpNqPxCcQclSmwcjLeVz1LtpnVM=; b=k19SIQ5VEeNuLy7kjQkTYNrPBrLhdRecIN6p7FHlK23FJprilH328fUWGmpI3oYNVw dnqd1yhrnaP9LzADBDRVUr8ltVvsbC7FGCHgLq2cMtXHFr/Ip3TyLDghKPZQh5kgN+2O uqz7KxfBOMKBJaXxLV6ISNSVNqs+YrIJ87rTCslz+L88/JbwhzbDY8dOizQPYP2pj8dU J7+JhYqNpu5jh6NsAQ/MD8rVcxXIty+W2o5IRbwrWVgMwHuxOlciNlrPbwES52LstifI nDg4N1UgY9Z9jUZowYx1u3Hav/E21Qj4/4ysWLXktHCmpYg6sNWRdc8STmcl9KfAUQ0z QzRw== 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=YyOgyO63SOQpzUzoJpNqPxCcQclSmwcjLeVz1LtpnVM=; b=V3xUwfQZPPAB85v/B5LNn+OOtgNcjA81WZGchzjXDga6GfsLyez249E3MKeke50eV+ mNhy9u2zqy7t3wJQJO8aTP+hr2wQznj3Tdnlcz/kX3vnmmXDMSxopE0zBDB395k8e58H fv1C7q00UjhF0/ZqZflMuePv9vc9LxogtavfhG5jWkncbWFBUnMX2PlEalHUz+kJGpJv mfp0W56Rjse50FuaTTtWil3fFkBFPa0sv2mwUMf0KPIqfEnjvY5A+DN9Dxj4AJpsAxfg 4qJui6LMhAPw1UyPqULZtAIV8FJDVHq9WfTBVe94ytKAFTGRVEMuQrPKHXXNo4Qw5pmU h2gA== X-Gm-Message-State: AOAM531ERsiIfzCFdXSvVI/pjF7mBpwjPafXtzgLec4NzqMjk2ROVx6r GKwZeUMWtFk4mjRc2EvmS/YGI8u3Fos/vA== X-Google-Smtp-Source: ABdhPJwJV8uYvqSyRSR2TfTJ2Fm1kwoXcDWguGNPlexi3a5/mXGaLFAugNlwCE1mAhEEooTIJKEzLg== X-Received: by 2002:a05:6830:1dae:: with SMTP id z14mr11298704oti.348.1628657860876; Tue, 10 Aug 2021 21:57:40 -0700 (PDT) Received: from localhost (fixed-187-189-69-1.totalplay.net. [187.189.69.1]) by smtp.gmail.com with ESMTPSA id h9sm1108060otr.67.2021.08.10.21.57.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Aug 2021 21:57:40 -0700 (PDT) From: Felipe Contreras To: git@vger.kernel.org Cc: Jonathan Nieder , Matthieu Moy , Michael J Gruber , Felipe Contreras Subject: [PATCH 7/7] stage: add 'edit' command Date: Tue, 10 Aug 2021 23:57:27 -0500 Message-Id: <20210811045727.2381-8-felipe.contreras@gmail.com> X-Mailer: git-send-email 2.32.0.48.g096519100f In-Reply-To: <20210811045727.2381-1-felipe.contreras@gmail.com> References: <20210811045727.2381-1-felipe.contreras@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Signed-off-by: Felipe Contreras --- Documentation/git-stage.txt | 5 +++ builtin/stage.c | 76 ++++++++++++++++++++++++++++++++++++- t/t3710-stage.sh | 6 +++ 3 files changed, 86 insertions(+), 1 deletion(-) diff --git a/Documentation/git-stage.txt b/Documentation/git-stage.txt index 460a8d6228..baea9d96e0 100644 --- a/Documentation/git-stage.txt +++ b/Documentation/git-stage.txt @@ -13,6 +13,7 @@ SYNOPSIS 'git stage' (-a | --add) [options] [--] [...] 'git stage' (-r | --remove) [options] [--] [...] 'git stage' (-d | --diff) [options] [--] [...] +'git stage' (-e | --edit) DESCRIPTION @@ -37,6 +38,10 @@ OPTIONS --diff:: View the changes staged for the next commit. See linkgit:git-diff[1]. +-e:: +--edit:: + Edit the changes in the staging area. + SEE ALSO -------- linkgit:git-add[1] diff --git a/builtin/stage.c b/builtin/stage.c index c57bb2d683..49af18dda7 100644 --- a/builtin/stage.c +++ b/builtin/stage.c @@ -5,6 +5,9 @@ #include "builtin.h" #include "parse-options.h" #include "run-command.h" +#include "diff.h" +#include "diffcore.h" +#include "revision.h" static const char *const stage_usage[] = { N_("git stage [options] [--] ..."), @@ -40,14 +43,83 @@ static int rerun(int argc, const char **argv, ...) return ret; } +static int do_reset(const char *prefix) +{ + const char *argv[] = { "reset", "--quiet", NULL }; + return run_command_v_opt(argv, RUN_GIT_CMD); +} + +static int do_apply(const char *file, const char *prefix) +{ + const char *argv[] = { "apply", "--recount", "--cached", file, NULL }; + return run_command_v_opt(argv, RUN_GIT_CMD); +} + +static int run_edit(int argc, const char **argv, const char *prefix) +{ + char *file = git_pathdup("STAGE_EDIT.patch"); + int out; + struct rev_info rev; + int ret = 0; + struct stat st; + + repo_read_index(the_repository); + + repo_init_revisions(the_repository, &rev, prefix); + rev.diffopt.context = 7; + + argc = setup_revisions(argc, argv, &rev, NULL); + add_head_to_pending(&rev); + if (!rev.pending.nr) { + struct tree *tree; + tree = lookup_tree(the_repository, the_repository->hash_algo->empty_tree); + add_pending_object(&rev, &tree->object, "HEAD"); + } + + rev.diffopt.output_format = DIFF_FORMAT_PATCH; + rev.diffopt.use_color = 0; + rev.diffopt.flags.ignore_dirty_submodules = 1; + + out = open(file, O_CREAT | O_WRONLY, 0666); + if (out < 0) + die(_("Could not open '%s' for writing."), file); + rev.diffopt.file = xfdopen(out, "w"); + rev.diffopt.close_file = 1; + + if (run_diff_index(&rev, DIFF_INDEX_CACHED)) + die(_("Could not write patch")); + if (launch_editor(file, NULL, NULL)) + exit(1); + + if (stat(file, &st)) + die_errno(_("Could not stat '%s'"), file); + + ret = do_reset(prefix); + if (ret) + goto leave; + + if (!st.st_size) + goto leave; + + ret = do_apply(file, prefix); + if (ret) + goto leave; + +leave: + unlink(file); + free(file); + return ret; +} + int cmd_stage(int argc, const char **argv, const char *prefix) { - int add = 0, remove = 0, diff = 0; + int add = 0, remove = 0, diff = 0, edit = 0; struct option options[] = { OPT_BOOL_F('a', "add", &add, N_("add changes"), PARSE_OPT_NONEG), OPT_BOOL_F('r', "remove", &remove, N_("remove changes"), PARSE_OPT_NONEG), OPT_BOOL_F('d', "diff", &diff, N_("show changes"), PARSE_OPT_NONEG), + OPT_BOOL_F('e', "edit", &edit, N_("edit changes"), PARSE_OPT_NONEG), OPT_END() }; @@ -58,6 +130,8 @@ int cmd_stage(int argc, const char **argv, const char *prefix) return rerun(argc, argv, "reset", NULL); if (diff) return rerun(argc, argv, "diff", "--staged", NULL); + if (edit) + return run_edit(argc, argv, prefix); return rerun(argc, argv, "add", NULL); } diff --git a/t/t3710-stage.sh b/t/t3710-stage.sh index aab979c20c..3c9522249f 100755 --- a/t/t3710-stage.sh +++ b/t/t3710-stage.sh @@ -42,4 +42,10 @@ test_expect_success 'diff' ' test_file_not_empty out ' +test_expect_success 'edit' ' + GIT_EDITOR="sed -i -e \"s/^+foo$/+edit/\"" git stage --edit && + git stage --diff > out && + grep "^+edit$" out +' + test_done