git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Add support for `git rebase -no-edit`
@ 2024-01-11 17:25 Chaitanya Tata
  2024-01-11 19:55 ` Taylor Blau
  2024-01-11 21:30 ` Junio C Hamano
  0 siblings, 2 replies; 6+ messages in thread
From: Chaitanya Tata @ 2024-01-11 17:25 UTC (permalink / raw)
  To: git

Hi,

I have a feature request to add `--no-edit` option to `git rebase`
like we do for `git commit`.
The workflow I typically follow is:

* `git commit -a --fixup=XXX`
* `git rebase  -i HEAD~15 --autosquash`

But it requires closing the editor without any changes. I can
workaround this using the `GIT_EDITOR` option, see [1]. But it would
be good to have this built-in.

Thoughts?

[1] - https://stackoverflow.com/a/45783848

Cheers,
Chaitanya.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Add support for `git rebase -no-edit`
  2024-01-11 17:25 Add support for `git rebase -no-edit` Chaitanya Tata
@ 2024-01-11 19:55 ` Taylor Blau
  2024-01-11 20:07   ` Chaitanya Tata
  2024-01-11 21:30 ` Junio C Hamano
  1 sibling, 1 reply; 6+ messages in thread
From: Taylor Blau @ 2024-01-11 19:55 UTC (permalink / raw)
  To: Chaitanya Tata; +Cc: git

Hi Chaitanya,

On Thu, Jan 11, 2024 at 10:55:47PM +0530, Chaitanya Tata wrote:
> Hi,
>
> I have a feature request to add `--no-edit` option to `git rebase`
> like we do for `git commit`.
> The workflow I typically follow is:
>
> * `git commit -a --fixup=XXX`
> * `git rebase  -i HEAD~15 --autosquash`
>
> But it requires closing the editor without any changes. I can
> workaround this using the `GIT_EDITOR` option, see [1]. But it would
> be good to have this built-in.

The easiest workaround would be setting GIT_EDITOR=true, which matches
the recommendation in [1].

Short of that, you can't do a non-interactive rebase, since we rely on
the todo list generated by interactive rebases in order for
`--autosquash` to work.

Presumably plumbing in a new `--[no-]edit` option would be fairly
straightforward, and once that is done, the change boils down to just:

index 3cc88d8a80..5235a003f2 100644
--- a/sequencer.c
+++ b/sequencer.c
@@ -6169,7 +6169,7 @@ int complete_action(struct repository *r, struct replay_opts *opts, unsigned fla
 	struct todo_list new_todo = TODO_LIST_INIT;
 	struct strbuf *buf = &todo_list->buf, buf2 = STRBUF_INIT;
 	struct object_id oid = onto->object.oid;
-	int res;
+	int res = 0;

 	repo_find_unique_abbrev_r(r, shortonto, &oid,
 				  DEFAULT_ABBREV);
@@ -6197,8 +6197,9 @@ int complete_action(struct repository *r, struct replay_opts *opts, unsigned fla
 		return error(_("nothing to do"));
 	}

-	res = edit_todo_list(r, todo_list, &new_todo, shortrevisions,
-			     shortonto, flags);
+	if (!opts->edit)
+		res = edit_todo_list(r, todo_list, &new_todo, shortrevisions,
+				     shortonto, flags);
 	if (res == -1)
 		return -1;
 	else if (res == -2) {

> [1] - https://stackoverflow.com/a/45783848

Thanks,
Taylor

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: Add support for `git rebase -no-edit`
  2024-01-11 19:55 ` Taylor Blau
@ 2024-01-11 20:07   ` Chaitanya Tata
  0 siblings, 0 replies; 6+ messages in thread
From: Chaitanya Tata @ 2024-01-11 20:07 UTC (permalink / raw)
  To: Taylor Blau; +Cc: git

Cheers,
Chaitanya.

On Fri, Jan 12, 2024 at 1:25 AM Taylor Blau <me@ttaylorr.com> wrote:
>
> Hi Chaitanya,
>
> On Thu, Jan 11, 2024 at 10:55:47PM +0530, Chaitanya Tata wrote:
> > Hi,
> >
> > I have a feature request to add `--no-edit` option to `git rebase`
> > like we do for `git commit`.
> > The workflow I typically follow is:
> >
> > * `git commit -a --fixup=XXX`
> > * `git rebase  -i HEAD~15 --autosquash`
> >
> > But it requires closing the editor without any changes. I can
> > workaround this using the `GIT_EDITOR` option, see [1]. But it would
> > be good to have this built-in.
>
> The easiest workaround would be setting GIT_EDITOR=true, which matches
> the recommendation in [1].
Thanks for the quick response.
>
> Short of that, you can't do a non-interactive rebase, since we rely on
> the todo list generated by interactive rebases in order for
> `--autosquash` to work.
IIUC, creating a todo list needs access to the file used in interactive
rebase?

> Presumably plumbing in a new `--[no-]edit` option would be fairly
> straightforward, and once that is done, the change boils down to just:
I am bit confused by this as this seems to contradict above statement,
I guess the below patch will only work without `--autosquash`? Sorry, not
familiar with git internals.
>
> index 3cc88d8a80..5235a003f2 100644
> --- a/sequencer.c
> +++ b/sequencer.c
> @@ -6169,7 +6169,7 @@ int complete_action(struct repository *r, struct replay_opts *opts, unsigned fla
>         struct todo_list new_todo = TODO_LIST_INIT;
>         struct strbuf *buf = &todo_list->buf, buf2 = STRBUF_INIT;
>         struct object_id oid = onto->object.oid;
> -       int res;
> +       int res = 0;
>
>         repo_find_unique_abbrev_r(r, shortonto, &oid,
>                                   DEFAULT_ABBREV);
> @@ -6197,8 +6197,9 @@ int complete_action(struct repository *r, struct replay_opts *opts, unsigned fla
>                 return error(_("nothing to do"));
>         }
>
> -       res = edit_todo_list(r, todo_list, &new_todo, shortrevisions,
> -                            shortonto, flags);
> +       if (!opts->edit)
> +               res = edit_todo_list(r, todo_list, &new_todo, shortrevisions,
> +                                    shortonto, flags);
>         if (res == -1)
>                 return -1;
>         else if (res == -2) {
>
> > [1] - https://stackoverflow.com/a/45783848
>
> Thanks,
> Taylor

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Add support for `git rebase -no-edit`
  2024-01-11 17:25 Add support for `git rebase -no-edit` Chaitanya Tata
  2024-01-11 19:55 ` Taylor Blau
@ 2024-01-11 21:30 ` Junio C Hamano
  2024-01-11 21:42   ` Taylor Blau
  1 sibling, 1 reply; 6+ messages in thread
From: Junio C Hamano @ 2024-01-11 21:30 UTC (permalink / raw)
  To: Chaitanya Tata; +Cc: git

Chaitanya Tata <chaitanya.tk17@gmail.com> writes:

> Hi,
>
> I have a feature request to add `--no-edit` option to `git rebase`
> like we do for `git commit`.
> The workflow I typically follow is:
>
> * `git commit -a --fixup=XXX`
> * `git rebase  -i HEAD~15 --autosquash`
>
> But it requires closing the editor without any changes. I can
> workaround this using the `GIT_EDITOR` option, see [1]. But it would
> be good to have this built-in.
>
> Thoughts?

With what is in the 'master' branch, you do not have to say
interactive when you do not want to go interactive.  I.e.

    $ git rebase --autosquash HEAD~15

should work fine.  Building Git from the source should not be too
hard.

By the way, make it a habit to pass non-option argument after dashed
options.  It is easier for your readers to understand your command
line that way.

Thanks.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Add support for `git rebase -no-edit`
  2024-01-11 21:30 ` Junio C Hamano
@ 2024-01-11 21:42   ` Taylor Blau
  2024-01-11 21:46     ` Chaitanya Tata
  0 siblings, 1 reply; 6+ messages in thread
From: Taylor Blau @ 2024-01-11 21:42 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: Chaitanya Tata, git

On Thu, Jan 11, 2024 at 01:30:55PM -0800, Junio C Hamano wrote:
> Chaitanya Tata <chaitanya.tk17@gmail.com> writes:
>
> > Hi,
> >
> > I have a feature request to add `--no-edit` option to `git rebase`
> > like we do for `git commit`.
> > The workflow I typically follow is:
> >
> > * `git commit -a --fixup=XXX`
> > * `git rebase  -i HEAD~15 --autosquash`
> >
> > But it requires closing the editor without any changes. I can
> > workaround this using the `GIT_EDITOR` option, see [1]. But it would
> > be good to have this built-in.
> >
> > Thoughts?
>
> With what is in the 'master' branch, you do not have to say
> interactive when you do not want to go interactive.  I.e.
>
>     $ git rebase --autosquash HEAD~15
>
> should work fine.  Building Git from the source should not be too
> hard.

Oh, duh. Indeed, 297be59456 (rebase: support --autosquash without -i,
2023-11-14) will do what Chaitanya is looking for. I'll give myself pass
on remembering that patch since it is from last year ;-).

Thanks,
Taylor

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Add support for `git rebase -no-edit`
  2024-01-11 21:42   ` Taylor Blau
@ 2024-01-11 21:46     ` Chaitanya Tata
  0 siblings, 0 replies; 6+ messages in thread
From: Chaitanya Tata @ 2024-01-11 21:46 UTC (permalink / raw)
  To: Taylor Blau; +Cc: Junio C Hamano, git

On Fri, Jan 12, 2024 at 3:12 AM Taylor Blau <me@ttaylorr.com> wrote:
>
> On Thu, Jan 11, 2024 at 01:30:55PM -0800, Junio C Hamano wrote:
> > Chaitanya Tata <chaitanya.tk17@gmail.com> writes:
> >
> > > Hi,
> > >
> > > I have a feature request to add `--no-edit` option to `git rebase`
> > > like we do for `git commit`.
> > > The workflow I typically follow is:
> > >
> > > * `git commit -a --fixup=XXX`
> > > * `git rebase  -i HEAD~15 --autosquash`
> > >
> > > But it requires closing the editor without any changes. I can
> > > workaround this using the `GIT_EDITOR` option, see [1]. But it would
> > > be good to have this built-in.
> > >
> > > Thoughts?
> >
> > With what is in the 'master' branch, you do not have to say
> > interactive when you do not want to go interactive.  I.e.
> >
> >     $ git rebase --autosquash HEAD~15
> >
> > should work fine.  Building Git from the source should not be too
> > hard.
Amazing, exactly what I need. And or arg order, I just typed in the command,
I typically use aliases that are in the proper order, but thanks.
>
> Oh, duh. Indeed, 297be59456 (rebase: support --autosquash without -i,
> 2023-11-14) will do what Chaitanya is looking for. I'll give myself pass
> on remembering that patch since it is from last year ;-).
:).

Thanks both for prompt support, I will compile and test this.

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2024-01-11 21:46 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-01-11 17:25 Add support for `git rebase -no-edit` Chaitanya Tata
2024-01-11 19:55 ` Taylor Blau
2024-01-11 20:07   ` Chaitanya Tata
2024-01-11 21:30 ` Junio C Hamano
2024-01-11 21:42   ` Taylor Blau
2024-01-11 21:46     ` Chaitanya Tata

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 NNTP newsgroup(s).