git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Sahil Dua <sahildua2305@gmail.com>
To: "Ævar Arnfjörð Bjarmason" <avarab@gmail.com>
Cc: Git Mailing List <git@vger.kernel.org>,
	Jonathan Nieder <jrnieder@gmail.com>
Subject: Re: [PATCH/RFC] branch: add tests for new copy branch feature
Date: Tue, 30 May 2017 00:23:36 +0200	[thread overview]
Message-ID: <CALiud+n3TPNCy4WNRjdaKpEU0yNh=UNAKx96pHqmi-X1sYChxA@mail.gmail.com> (raw)
In-Reply-To: <CACBZZX6LcTzFKTe0fENj95Vm7GrxT5HHs3pzrqajG0XApN-rbw@mail.gmail.com>

On Mon, May 29, 2017 at 10:50 PM, Ævar Arnfjörð Bjarmason
<avarab@gmail.com> wrote:
> On Mon, May 29, 2017 at 10:41 PM, Sahil Dua <sahildua2305@gmail.com> wrote:
>> On Mon, May 29, 2017 at 1:30 AM, Ævar Arnfjörð Bjarmason
>> <avarab@gmail.com> wrote:
>>> On Mon, May 29, 2017 at 12:56 AM, Sahil Dua <sahildua2305@gmail.com> wrote:
>>>> New feature - copying a branch along with its config section.
>>>>
>>>> Aim is to have an option -c for copying a branch just like -m option for
>>>> renaming a branch.
>>>>
>>>> This commit adds a few basic tests for getting any suggestions/feedback
>>>> about expected behavior for this new feature.
>>>>
>>>> Signed-off-by: Sahil Dua <sahildua2305@gmail.com>
>>>> ---
>>>>  t/t3200-branch.sh | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++++
>>>>  1 file changed, 53 insertions(+)
>>>>
>>>> diff --git a/t/t3200-branch.sh b/t/t3200-branch.sh
>>>> index fe62e7c775da..2c95ed6ebf3c 100755
>>>> --- a/t/t3200-branch.sh
>>>> +++ b/t/t3200-branch.sh
>>>> @@ -341,6 +341,59 @@ test_expect_success 'config information was renamed, too' '
>>>>         test_must_fail git config branch.s/s/dummy
>>>>  '
>>>>
>>>> +test_expect_success 'git branch -c dumps usage' '
>>>> +       test_expect_code 128 git branch -c 2>err &&
>>>> +       test_i18ngrep "branch name required" err
>>>> +'
>>>> +
>>>> +git config branch.d.dummy Hello
>>>> +
>>>> +test_expect_success 'git branch -c d e should work' '
>>>> +       git branch -l d &&
>>>> +       git reflog exists refs/heads/d &&
>>>> +       git branch -c d e &&
>>>> +       git reflog exists refs/heads/d &&
>>>> +       git reflog exists refs/heads/e
>>>> +'
>>>> +
>>>> +test_expect_success 'config information was copied, too' '
>>>> +       test $(git config branch.e.dummy) = Hello &&
>>>> +       test $(git config branch.d.dummy) = Hello
>>>> +'
>>>> +
>>>> +git config branch.f/f.dummy Hello
>>>> +
>>>> +test_expect_success 'git branch -c f/f g/g should work' '
>>>> +       git branch -l f/f &&
>>>> +       git reflog exists refs/heads/f/f &&
>>>> +       git branch -c f/f g/g &&
>>>> +       git reflog exists refs/heads/f/f &&
>>>> +       git reflog exists refs/heads/g/g
>>>> +'
>>>> +
>>>> +test_expect_success 'config information was copied, too' '
>>>> +       test $(git config branch.f/f.dummy) = Hello &&
>>>> +       test $(git config branch.g/g.dummy) = Hello
>>>> +'
>>>> +
>>>> +test_expect_success 'git branch -c m2 m2 should work' '
>>>> +       git branch -l m2 &&
>>>> +       git reflog exists refs/heads/m2 &&
>>>> +       git branch -c m2 m2 &&
>>>> +       git reflog exists refs/heads/m2
>>>> +'
>>>> +
>>>> +test_expect_success 'git branch -c a a/a should fail' '
>>>> +       git branch -l a &&
>>>> +       git reflog exists refs/heads/a &&
>>>> +       test_must_fail git branch -c a a/a
>>>> +'
>>>> +
>>>> +test_expect_success 'git branch -c b/b b should fail' '
>>>> +       git branch -l b/b &&
>>>> +       test_must_fail git branch -c b/b b
>>>> +'
>>>> +
>>>>  test_expect_success 'deleting a symref' '
>>>>         git branch target &&
>>>>         git symbolic-ref refs/heads/symref refs/heads/target &&
>>>>
>>>
>>> This looks good to me. Comments, in no particular order:
>>>
>>> * There should be a test for `git branch -c <newbranch>`, i.e. that
>>> should implicitly copy from HEAD just like `git branch -m <newbranch>`
>>> does. However, when looking at this I can see there's actually no test
>>> for one-argument `git branch -m`, i.e. if you apply this:
>>>
>>> --- a/builtin/branch.c
>>> +++ b/builtin/branch.c
>>> @@ -699,8 +699,6 @@ int cmd_branch(int argc, const char **argv, const
>>> char *prefix)
>>>         } else if (rename) {
>>>                 if (!argc)
>>>                         die(_("branch name required"));
>>> -               else if (argc == 1)
>>> -                       rename_branch(head, argv[0], rename > 1);
>>>                 else if (argc == 2)
>>>                         rename_branch(argv[0], argv[1], rename > 1);
>>>                 else
>>>
>>> The only test that fails is a `git branch -M master`, i.e.
>>> one-argument -M is tested for, but not -m, same codepath though, but
>>> while you're at it a patch/series like this could start by adding a
>>> one-arg -m test, then follow-up by copying that for the new `-c`.
>>>
>>
>> Thanks for the suggestion. Yes, I will add one-arg test for -c. Is it
>> ok to send a different patch for adding a one-arg test for existing -m
>> option?
>
> Yeah, it makes sense to just make the first patch in the series be
> some cleanup / improvement of the existing tests, which the subsequent
> tests for -c then make use of / copy. It could even be sent on its
> own, but probably makes sense to just bundle them up. Up to you
> though, in this case you won't need patch A for patch B to work, so
> the that's one argument against bundling them up. Personally I'd do it
> if I was hacking this just because it's more convenient to keep track
> of fewer things.
>

Got it. I will submit a patch for the tests for -m option.

>>> * We should have a -C to force -c just like -M forces -m, i.e. a test
>>> where one-arg `git branch -C alreadyexists` clobbers alreadyexists,
>>> and `git branch -C source alreadyexists` does the same for two-arg.
>>>
>> Yes, I missed this. I will add -C option too.
>>
>>> * I know this is just something you're copying, but this `git branch
>>> -l <name>` use gets me every time "wait how does listing it help isn't
>>> that always succeeding ... damnit it's --create-reflog not --list, got
>>> me again" :)
>>>
>>
>> Yes, it was confusing to me too in the beginning. I will use --create-reflog.
>>
>>> Just noting it in case it confuses other reviewers who are skimming
>>> this. Might be worth it to just use --create-reflog for new tests
>>> instead of the non-obvious -l whatever the existing tests in the file
>>> do, or maybe I'm the only one confused by this :)
>>>
>>> * When you use `git branch -m` it adds a note to the reflog, your
>>> patch should have a test like the existing "git branch -M baz bam
>>> should add entries to .git/logs/HEAD" test in this file except
>>> "Branch: copied ..." instead of "Branch: renamed...".
>>>
>>
>> Nice, I will add it. Thanks.
>>
>>> * Should there be tests for `git branch -c master master` like we have
>>> for `git branch -m master master` (see 3f59481e33 ("branch: allow a
>>> no-op "branch -M <current-branch> HEAD"", 2011-11-25)). Allowing this
>>> for -m smells like a bend-over-backwards workaround for some script
>>> Jonathan had, should we be doing this for -c too? I don't know.
>>
>> Not sure I understand this. Can you please elaborate?
>> Thanks.
>
> So the reason we have this for -m is:
>
>     commit 3f59481e33
>     Author: Jonathan Nieder <jrnieder@gmail.com>
>     Date:   Fri Nov 25 20:30:02 2011 -0600
>
>     branch: allow a no-op "branch -M <current-branch> HEAD"
>
>     Overwriting the current branch with a different commit is forbidden, as it
>     will make the status recorded in the index and the working tree out of
>     sync with respect to the HEAD. There however is no reason to forbid it if
>     the current branch is renamed to itself, which admittedly is something
>     only an insane user would do, but is handy for scripts.
>
> My understanding of that last part is that Jonathan/someone (see
> reported-by in that patch) had some script which was renaming
> branches, and it was easier for whatever reason to just make it no-op
> if the rename would have yielded the same result as doing nothing at
> all.
>
> Most likely your implementation will consist of just re-using the
> logic in rename_branch() (and renaming it to e.g.
> copy_or_rename_branch() ...) so you could just re-use the no-op
> behavior we use for -m, or if there's some reason not to no-op and
> error instead for -c we could just do that, but in any case this case
> of `git branch -c master master` or `git branch -c currentbranch`
> should be tested for.

Understood. Thanks. I will add tests for this too.

  reply	other threads:[~2017-05-29 22:24 UTC|newest]

Thread overview: 49+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-05-28 22:56 [PATCH/RFC] branch: add tests for new copy branch feature Sahil Dua
2017-05-28 23:30 ` Ævar Arnfjörð Bjarmason
2017-05-29 20:41   ` Sahil Dua
2017-05-29 20:50     ` Ævar Arnfjörð Bjarmason
2017-05-29 22:23       ` Sahil Dua [this message]
2017-06-13 17:55       ` Jonathan Nieder
2017-06-13 18:01         ` Ævar Arnfjörð Bjarmason
2017-06-13 18:08           ` Jonathan Nieder
2017-05-29  2:09 ` Junio C Hamano
2017-05-29 19:39   ` Sahil Dua
2017-05-31 23:35 ` [PATCH/RFC v2 1/6] " Sahil Dua
2017-05-31 23:35   ` [PATCH/RFC v2 2/6] branch: add copy branch option Sahil Dua
2017-06-01  1:50     ` Junio C Hamano
2017-06-01 16:09       ` Sahil Dua
2017-05-31 23:35   ` [PATCH/RFC v2 4/6] config: modify function signature to include copy argument Sahil Dua
2017-05-31 23:35   ` [PATCH/RFC v2 5/6] config: add copy config section logic Sahil Dua
2017-05-31 23:35   ` [PATCH/RFC v2 6/6] branch: don't copy or rename config when same branch name Sahil Dua
2017-05-31 23:35   ` [PATCH/RFC v2 3/6] config: abstract out create section from key logic Sahil Dua
2017-06-01 18:35   ` [PATCH/RFC v3 1/3] branch: add tests for new copy branch feature Sahil Dua
2017-06-01 18:35     ` [PATCH/RFC v3 2/3] config: abstract out create section from key logic Sahil Dua
2017-06-01 18:35     ` [PATCH/RFC v3 3/3] branch: add copy branch feature implementation Sahil Dua
2017-06-01 18:59       ` Ævar Arnfjörð Bjarmason
2017-06-01 22:05         ` Sahil Dua
2017-06-05 20:40     ` [PATCH/RFC v4 1/3] branch: add tests for new copy branch feature Sahil Dua
2017-06-05 20:40       ` [PATCH/RFC v4 2/3] config: abstract out create section from key logic Sahil Dua
2017-06-05 20:40       ` [PATCH/RFC v4 3/3] branch: add copy branch feature implementation Sahil Dua
2017-06-05 20:52         ` Sahil Dua
2017-06-06  0:10           ` Junio C Hamano
2017-06-06  0:14             ` Junio C Hamano
2017-06-06  7:39             ` Ævar Arnfjörð Bjarmason
2017-06-06 10:13               ` Sahil Dua
2017-06-06 12:03               ` Junio C Hamano
2017-06-13 16:17       ` [PATCH 1/3] config: create a function to format section headers Sahil Dua
2017-06-13 16:17         ` [PATCH 2/3] branch: add test for -m renaming multiple config sections Sahil Dua
2017-06-13 17:10           ` Junio C Hamano
2017-06-13 17:31             ` Ævar Arnfjörð Bjarmason
2017-06-13 17:39               ` Junio C Hamano
2017-06-13 17:53                 ` Ævar Arnfjörð Bjarmason
2017-06-18 21:17           ` [PATCH v2 " Sahil Dua
2017-06-13 16:17         ` [PATCH 3/3] branch: add a --copy (-c) option to go with --move (-m) Sahil Dua
2017-06-13 17:05           ` Junio C Hamano
2017-06-13 17:30             ` Junio C Hamano
2017-06-14  8:01               ` Sahil Dua
2017-06-18 21:19           ` [PATCH v2 " Sahil Dua
2017-06-13 17:06         ` [PATCH 1/3] config: create a function to format section headers Junio C Hamano
2017-06-13 17:09         ` Ævar Arnfjörð Bjarmason
2017-06-18 21:16         ` [PATCH v2 " Sahil Dua
2017-06-19 12:08           ` Ramsay Jones
2017-06-19 14:51             ` Sahil Dua

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='CALiud+n3TPNCy4WNRjdaKpEU0yNh=UNAKx96pHqmi-X1sYChxA@mail.gmail.com' \
    --to=sahildua2305@gmail.com \
    --cc=avarab@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=jrnieder@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.
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).