git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: Stefan Beller <sbeller@google.com>
Cc: Philip Oakley <philipoakley@iee.org>, Jeff King <peff@peff.net>,
	Orgad Shaneh <orgads@gmail.com>,
	Dakota Hawkins <dakotahawkins@gmail.com>,
	git <git@vger.kernel.org>,
	Christoph Michelbach <michelbach94@gmail.com>
Subject: Re: Submodule/contents conflict
Date: Wed, 26 Apr 2017 17:25:33 -0700	[thread overview]
Message-ID: <xmqqmvb2r91e.fsf@gitster.mtv.corp.google.com> (raw)
In-Reply-To: <CAGZ79kZEveo8jQodvd0n6fEXc1OXDVa26BCumM0etjst74F_Hw@mail.gmail.com> (Stefan Beller's message of "Wed, 26 Apr 2017 10:41:11 -0700")

Stefan Beller <sbeller@google.com> writes:

> I assumed a use case like this:
>
>   A user may want to extract a file from a given tree-ish via
>   GIT_WORK_TREE=/tmp/place git checkout <tree> -- <file>
>   without modifying the repository (i.e. index) at all. For this
>   we'd need an option to modify the working tree only.

I somehow do not see that as a very useful use case.  It is not just
keeping the index, but it is depositing the file also out of the
working tree, and if you do not want to work with the resulting
<file> (actually, if it is a single file, "cat-file -t blob" is the
most natural thing to use for such an operation, so you should say
<pathspec> that may match multiple files and perhaps a collection of
directories) within the context of your working tree, I would think
that "archive | tar xf -" is a better choice.

The feature is more about in-tree case.  You clobber what you did in
your working tree by extracting a pristine copy out of some known
tree, which may not be HEAD.  And if the tree is not HEAD, you would
want "git diff <pathspec>" would give a useful preview of what would
happen when you do "git add" them.  As "checkout" adds to the index
before updating the working tree (which can be argued as an ancient
design mistake, given that we typically do worktree-only by default
and have "--index/--cached" to work with the index, e.g. "apply",
"grep"), the user needs to do "git diff HEAD <pathspec>" instead in
this case.

> I never realized this as a usual convention explicitly. Thanks for pointing
> it out.

I think it is somewhere in gitcli(7).

>> +       if (opts->no_index && !opts->source_tree)
>> +               die(_("'--working-tree-only' cannot be used without tree-ish"));
>
> double negation, maybe:
>
>   "--working-tree-only requires tree-ish"

Much more concise.  Thanks.

>> +test_expect_success 'working-tree-only option leaves checked out files unadded' '
>> +       git reset --hard &&
>> +       git checkout -b pu next &&
>> +       echo another >>file1 &&
>> +       echo exists >file3 &&
>> +       git add file3 &&
>> +       git commit -a -m another &&
>> +       git checkout next &&
>
> Up to here it is all preparation; I started to give an argument
> on why using "another" for both the commit message and the file content
> was suboptimal, but I was wrong. This seems to be best after some consideration.

It does add to the mental burden.  Will think of a pair of different
words and phrases.

> The next paragraph checks for
> 'working-tree-only option populates the working tree, but doesn't touch index'
>
>> +       ! grep another file1 &&
>> +       git checkout --working-tree-only pu file1 file3 &&
>> +       grep another file1 &&
>> +       test_must_fail git grep --cached another file1 &&
>
> but only for file1, whereas the next paragraph checks it for file3.
>
>> +       grep exists file3 &&
>> +       git ls-files file3 >actual &&
>> +       >expect &&
>> +       test_cmp expect actual

Yes.  This demonstrates that paths only in tree-ish is not added to
the index (i.e. ls-files does not show it, because HEAD and the
original index didn't have it).  If you did the same "grep --cached"
that expects a non-match, you cannot tell if we added the path with
the --intent-to-add or if we didn't add it at all, so it deliberately
checks different thing from the case for file1.

  reply	other threads:[~2017-04-27  0:25 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-04-24  8:06 Submodule/contents conflict Orgad Shaneh
2017-04-24 17:40 ` Stefan Beller
2017-04-24 23:33   ` Philip Oakley
2017-04-24 23:43     ` Stefan Beller
2017-04-25  3:22       ` Jeff King
2017-04-25  3:39         ` Jeff King
2017-04-27 22:52         ` Philip Oakley
2017-04-28  8:30           ` Jeff King
2017-05-01  0:15             ` Junio C Hamano
2017-04-25 11:10       ` Philip Oakley
2017-04-26  2:51         ` Junio C Hamano
2017-04-26 17:41           ` Stefan Beller
2017-04-27  0:25             ` Junio C Hamano [this message]
2017-04-27  0:29             ` Junio C Hamano
2017-04-27 22:07           ` Philip Oakley
2017-04-28  2:08             ` Junio C Hamano
2017-04-25  2:12   ` Junio C Hamano
2017-04-25 15:57     ` Stefan Beller

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

  List information: http://vger.kernel.org/majordomo-info.html

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

  git send-email \
    --in-reply-to=xmqqmvb2r91e.fsf@gitster.mtv.corp.google.com \
    --to=gitster@pobox.com \
    --cc=dakotahawkins@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=michelbach94@gmail.com \
    --cc=orgads@gmail.com \
    --cc=peff@peff.net \
    --cc=philipoakley@iee.org \
    --cc=sbeller@google.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.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

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 read-only IMAP folder(s) and NNTP newsgroup(s).