git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Eric Sunshine <sunshine@sunshineco.com>
To: "Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>
Cc: Git List <git@vger.kernel.org>,
	Junio C Hamano <gitster@pobox.com>,
	patrick@parcs.ath.cx
Subject: Re: [PATCH v2] reset: optionally setup worktree and refresh index on --mixed
Date: Sat, 15 Feb 2014 21:29:32 -0500	[thread overview]
Message-ID: <CAPig+cTFxwnAA807rAaRfU6HZWthZFxUKzaKoLmPBVs+v4pMSQ@mail.gmail.com> (raw)
In-Reply-To: <1392517683-29518-1-git-send-email-pclouds@gmail.com>

On Sat, Feb 15, 2014 at 9:28 PM, Nguyễn Thái Ngọc Duy <pclouds@gmail.com> wrote:
> Refreshing index requires work tree. So we have to options: always set

s/to/two/

> up work tree (and refuse to reset if failing to do so), or make
> refreshing index optional.
>
> As refreshing index is not the main task, it makes more sense to make
> it optional.
>
> Reported-by: Patrick Palka <patrick@parcs.ath.cx>
> Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
> ---
>  builtin/reset.c  |  7 ++++---
>  t/t7102-reset.sh | 11 +++++++++++
>  2 files changed, 15 insertions(+), 3 deletions(-)
>
> diff --git a/builtin/reset.c b/builtin/reset.c
> index 6004803..a991344 100644
> --- a/builtin/reset.c
> +++ b/builtin/reset.c
> @@ -320,7 +320,7 @@ int cmd_reset(int argc, const char **argv, const char *prefix)
>         if (reset_type == NONE)
>                 reset_type = MIXED; /* by default */
>
> -       if (reset_type != SOFT && reset_type != MIXED)
> +       if (reset_type != SOFT && (reset_type != MIXED || get_git_work_tree()))
>                 setup_work_tree();
>
>         if (reset_type == MIXED && is_bare_repository())
> @@ -340,8 +340,9 @@ int cmd_reset(int argc, const char **argv, const char *prefix)
>                         int flags = quiet ? REFRESH_QUIET : REFRESH_IN_PORCELAIN;
>                         if (read_from_tree(&pathspec, sha1))
>                                 return 1;
> -                       refresh_index(&the_index, flags, NULL, NULL,
> -                                     _("Unstaged changes after reset:"));
> +                       if (get_git_work_tree())
> +                               refresh_index(&the_index, flags, NULL, NULL,
> +                                             _("Unstaged changes after reset:"));
>                 } else {
>                         int err = reset_index(sha1, reset_type, quiet);
>                         if (reset_type == KEEP && !err)
> diff --git a/t/t7102-reset.sh b/t/t7102-reset.sh
> index 8d4b50d..ee117e2 100755
> --- a/t/t7102-reset.sh
> +++ b/t/t7102-reset.sh
> @@ -535,4 +535,15 @@ test_expect_success 'reset with paths accepts tree' '
>         git diff HEAD --exit-code
>  '
>
> +test_expect_success 'reset --mixed sets up work tree' '
> +       git init mixed_worktree &&
> +       (
> +               cd mixed_worktree &&
> +               test_commit dummy
> +       ) &&
> +       : >expect &&
> +       git --git-dir=mixed_worktree/.git --work-tree=mixed_worktree reset >actual &&
> +       test_cmp expect actual
> +'
> +
>  test_done
> --
> 1.8.5.2.240.g8478abd
>
> --
> To unsubscribe from this list: send the line "unsubscribe git" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html

  reply	other threads:[~2014-02-16  2:29 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-02-14 18:57 git-reset does not seem to respect GIT_WORK_TREE Patrick Palka
2014-02-15  9:14 ` [PATCH] reset: setup worktree on --mixed Nguyễn Thái Ngọc Duy
2014-02-15  9:38   ` Duy Nguyen
2014-02-16  2:28   ` [PATCH v2] reset: optionally setup worktree and refresh index " Nguyễn Thái Ngọc Duy
2014-02-16  2:29     ` Eric Sunshine [this message]
2014-02-16 18:19     ` Patrick Palka

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAPig+cTFxwnAA807rAaRfU6HZWthZFxUKzaKoLmPBVs+v4pMSQ@mail.gmail.com \
    --to=sunshine@sunshineco.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=patrick@parcs.ath.cx \
    --cc=pclouds@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).