All of lore.kernel.org
 help / color / mirror / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: "Elijah Newren via GitGitGadget" <gitgitgadget@gmail.com>
Cc: git@vger.kernel.org, Elijah Newren <newren@gmail.com>
Subject: Re: [PATCH] stash: do not return before restoring untracked files
Date: Tue, 04 Jan 2022 15:46:27 -0800	[thread overview]
Message-ID: <xmqqy23v83os.fsf@gitster.g> (raw)
In-Reply-To: <pull.1180.git.git.1641337498996.gitgitgadget@gmail.com> (Elijah Newren via GitGitGadget's message of "Tue, 04 Jan 2022 23:04:58 +0000")

"Elijah Newren via GitGitGadget" <gitgitgadget@gmail.com> writes:

> diff --git a/builtin/stash.c b/builtin/stash.c
> index 18c812bbe03..397210168da 100644
> --- a/builtin/stash.c
> +++ b/builtin/stash.c
> @@ -561,18 +561,19 @@ static int do_apply_stash(const char *prefix, struct stash_info *info,
>  		if (index)
>  			fprintf_ln(stderr, _("Index was not unstashed."));
>  
> -		return ret;
> +		goto restore_untracked;
>  	}
>  
>  	if (has_index) {
>  		if (reset_tree(&index_tree, 0, 0))
> -			return -1;
> +			ret = -1;
>  	} else {
>  		unstage_changes_unless_new(&c_tree);
>  	}
>  
> +restore_untracked:
>  	if (info->has_u && restore_untracked(&info->u_tree))
> -		return error(_("could not restore untracked files from stash"));
> +		ret = error(_("could not restore untracked files from stash"));

In other words, instead of doing an early return, we try to
resurrect untracked ones and always show the "git status" before
returning.

I think that takes us in the right direction.  I looked at other
early returns in this function, and while there may be a room for
improvements when the --index stash does not apply well, I think it
can be left outside the topic of this patch.

Will queue.

Thanks.

>  	if (!quiet) {
>  		struct child_process cp = CHILD_PROCESS_INIT;
> @@ -592,7 +593,7 @@ static int do_apply_stash(const char *prefix, struct stash_info *info,
>  		run_command(&cp);
>  	}
>  
> -	return 0;
> +	return ret;
>  }
>  
>  static int apply_stash(int argc, const char **argv, const char *prefix)
> diff --git a/t/t3903-stash.sh b/t/t3903-stash.sh
> index 2c66cfbc3b7..2a7d8e511db 100755
> --- a/t/t3903-stash.sh
> +++ b/t/t3903-stash.sh
> @@ -1376,4 +1376,28 @@ test_expect_success 'git stash can pop directory -> file saved changes' '
>  	)
>  '
>  
> +test_expect_success 'restore untracked files even when we hit conflicts' '
> +	git init restore_untracked_after_conflict &&
> +	(
> +		cd restore_untracked_after_conflict &&
> +
> +		echo hi >a &&
> +		echo there >b &&
> +		git add . &&
> +		git commit -m first &&
> +		echo hello >a &&
> +		echo something >c &&
> +
> +		git stash push --include-untracked &&
> +
> +		echo conflict >a &&
> +		git add a &&
> +		git commit -m second &&
> +
> +		test_must_fail git stash pop &&
> +
> +		test_path_is_file c
> +	)
> +'
> +
>  test_done
>
> base-commit: 2ae0a9cb8298185a94e5998086f380a355dd8907

      reply	other threads:[~2022-01-04 23:46 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-01-04 23:04 [PATCH] stash: do not return before restoring untracked files Elijah Newren via GitGitGadget
2022-01-04 23:46 ` Junio C Hamano [this message]

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=xmqqy23v83os.fsf@gitster.g \
    --to=gitster@pobox.com \
    --cc=git@vger.kernel.org \
    --cc=gitgitgadget@gmail.com \
    --cc=newren@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.