On Tue, Jun 13, 2017 at 7:10 PM, Junio C Hamano <gits...@pobox.com> wrote:
> Sahil Dua <sahildua2...@gmail.com> writes:
>
>> +     cat >expect <<-\EOF &&
>> +     branch.dest.key1=value1
>> +     some.gar.b=age
>> +     branch.dest.key2=value2
>> +     EOF
>> +     cat >config.branch <<\EOF &&
>> +;; Comment for source
>> +[branch "source"]
>> +     ;; Comment for the source value
>> +     key1 = value1
>> +     ;; Comment for some.gar
>> +[some "gar"]
>> +     ;; Comment for the some.gar value
>> +     b = age
>> +     ;; Comment for source, again
>> +[branch "source"]
>> +     ;; Comment for the source value, again
>> +     key2 = value2
>> +EOF
>
> Indenting using <<- would make it easier to read.  I.e.
>
>         cat >config.branch <<-\EOF &&
>         ;; Comment for ...
>         [branch "source"]
>                 ;; Comment for ...
>         ...
>         EOF

I should have added a comment for that, I can't find any portable (but
suggestions welcome) way to do that and preserve the indentation, so
the test_cmp would still succeed if the moving/renaming function
munged all leading whitespace in the config with -\EOF as opposed to
\EOF.

>> +     cat config.branch >>.git/config &&
>> +     git branch -m source dest &&
>> +     git config -f .git/config -l | grep -F -e source -e dest -e some.gar 
>> >actual &&
>> +     test_cmp expect actual &&
>> +
>> +     # ...and that the comments for those sections are also
>> +     # preserved.
>> +     cat config.branch | sed "s/\"source\"/\"dest\"/" >expect &&
>> +     grep -A 9001 "Comment for source" .git/config >actual &&
>
> Where does 9001 come from?  Is that just "an arbitrary large
> number"?
>
> Besides, "grep -A" is quite unportable.  Would
>
>         sed -n -e "/Comment for source/,$p" .git/config >actual
>
> work equally well?

It's just a sufficiently large number, I thought -A was portable
enough after grepping the test suite, but on closer inspection it
turns out those were all git-grep invocations, oops. Yeah all I need
here is all lines after a line matching a given string, so that sed
command works, will fix it up to use that.

>> +     test_cmp expect actual
>> +'
>> +
>>  test_expect_success 'deleting a symref' '
>>       git branch target &&
>>       git symbolic-ref refs/heads/symref refs/heads/target &&
>>
>> --
>> https://github.com/git/git/pull/363

Reply via email to