threads / discuss / 61604

Autosplit option for git add -p

Subject: Autosplit option for git add -p

## tl;dr

4 messages between Jun 7, 2024 and Jun 8, 2024.

replies: 3people: 4as markdown or json

Konstantin Tokarev· Jun 7, 2024, 09:05 UTC · lore
Hello all,

Is there any option in git to make `git add -p` split hunks by default, just like 's' was pressed automatically? If no, how would one implement such an option?

My use case: I've recently started working with big LaTeX document having every paragraph as a single line. As a result, hunks quickly become larger than screen, so that splitting is highly desirable.

Thanks.
Christian Couder· Jun 8, 2024, 10:43 UTC · re: Konstantin Tokarev · lore

Re: Autosplit option for git add -p

Hi,
On Fri, Jun 7, 2024 at 11:06 AM Konstantin Tokarev <annulen@yandex.ru> wrote:
Show 6 quoted lines
>
> Hello all,
>
> Is there any option in git to make `git add -p` split hunks by
> default, just like 's' was pressed automatically? If no, how would one
> implement such an option?

It doesn't look like there is any option to do that. About implementing it, it depends if it would be a command line option or a config option.

Anyway I think you might want to take a look at the run_add_p() function in "add-patch.c".

> My use case: I've recently started working with big LaTeX document
> having every paragraph as a single line. As a result, hunks quickly
> become larger than screen, so that splitting is highly desirable.
Best!
Dragan Simic· Jun 8, 2024, 10:47 UTC · re: Christian Couder · lore

Re: Autosplit option for git add -p

Hello,
On 2024-06-08 12:43, Christian Couder wrote:
Show 9 quoted lines
> On Fri, Jun 7, 2024 at 11:06 AM Konstantin Tokarev <annulen@yandex.ru> 
> wrote:
>> Is there any option in git to make `git add -p` split hunks by
>> default, just like 's' was pressed automatically? If no, how would one
>> implement such an option?
> 
> It doesn't look like there is any option to do that. About
> implementing it, it depends if it would be a command line option or a
> config option.

To me, a new command-line option would make more sense. Though, perhaps a new configuration option could also make sense when enabled for particular repositories, but that could also trigger the main red flag, which is that a repository configuration can change the user experience, so I'm not sure it wouldn't be frowned upon.

Show 6 quoted lines
> Anyway I think you might want to take a look at the run_add_p()
> function in "add-patch.c".
> 
>> My use case: I've recently started working with big LaTeX document
>> having every paragraph as a single line. As a result, hunks quickly
>> become larger than screen, so that splitting is highly desirable.
Junio C Hamano· Jun 8, 2024, 18:53 UTC · re: Christian Couder · lore

Re: Autosplit option for git add -p

Christian Couder <christian.couder@gmail.com> writes:
> It doesn't look like there is any option to do that. About
> implementing it, it depends if it would be a command line option or a
> config option.
Having these alone make no sense to me.

I'd suggest extending the lowest level (i.e. interactive prompt response) first so that a stronger 's' splits all hunks in the current file. It might be sufficient for the use case.

On top of that, it happens to be that when changes to _all_ paths want to be split, it may prove handy to also have a command line option.

But the reason why I am hesitant to endorse a command line option that splits everything is because:

 (1) it is dubious to expect the user to _know_ that it makes sense
     to split all changes before starting "add -p" (and friends).
 (2) if the user gives such an option and then in the interactive
     session regrets that it was too much to split all the hunks, it
     is unclear how the user can easily recover (there is no "merge
     all hunks back to the original" operation).

← back to recent threads