rebase: respect --ff-only option
RFC PATCH 1/1 rebase: respect --ff-only option
The warning about pulling without specifying how to reconcile divergent branches says that after setting pull.rebase to true, --ff-only can still be passed on the command line to require a fast-forward. Make that actually work.
---
I'm sending this patch as an RFC because I'm sure someone will find at least one thing that needs to be changed before it's committed.
--- advice.c | 6 +++ advice.h | 1 + builtin/merge.c | 6 --- builtin/pull.c | 2 + builtin/rebase.c | 68 +++++++++++++++++++------------ builtin/revert.c | 6 +-- sequencer.c | 53 ++++++++++++++---------- sequencer.h | 9 +++- t/t3404-rebase-interactive.sh | 5 +++ t/t3409-rebase-preserve-merges.sh | 4 ++ t/t3420-rebase-autostash.sh | 9 ++++ t/t7601-merge-pull-config.sh | 10 +++++ 12 files changed, 121 insertions(+), 58 deletions(-)
advice.c +6 -0
@@ -246,6 +246,12 @@ void list_config_advices(struct string_list *list, const char *prefix)list_config_item (list, prefix, advice_setting[i].key); } +int error_ff_impossible (void ) +{ +error (_ ("Not possible to fast-forward, aborting." )); +return -1 ; +} +int error_resolve_conflict (const char *me) {if (!strcmp (me,"cherry-pick" ))
advice.h +1 -0
@@ -93,6 +93,7 @@ int advice_enabled(enum advice_type type);void advise_if_enabled (enum advice_type type,const char *advice, ...);int error_resolve_conflict (const char *me); +int error_ff_impossible (void ); void NORETURN die_resolve_conflict(const char *me); void NORETURN die_conclude_merge(void);void advise_on_updating_sparse_paths (struct string_list *pathspec_list);
builtin/merge.c +0 -6
@@ -98,12 +98,6 @@ static struct strategy all_strategy[] = {static const char *pull_twohead, *pull_octopus; -enum ff_type { -FF_NO , -FF_ALLOW , -FF_ONLY -}; -static enum ff_type fast_forward =FF_ALLOW ;static const char *cleanup_arg;
builtin/pull.c +2 -0
@@ -889,6 +889,8 @@ static int run_rebase(const struct object_id *newbase,strvec_push (&args,"--interactive" );if (opt_diffstat)strvec_push (&args, opt_diffstat); +if (opt_ff) +strvec_push (&args, opt_ff);strvec_pushv (&args, opt_strategies.v);strvec_pushv (&args, opt_strategy_opts.v);if (opt_gpg_sign)
builtin/rebase.c +41 -27
137 lines not on this page · raw message
builtin/revert.c +3 -3
@@ -123,7 +123,7 @@ static int run_sequencer(int argc, const char **argv, struct replay_opts *opts)if (opts->action ==REPLAY_PICK ) {struct option cp_extra[] = {OPT_BOOL ('x' ,NULL , &opts->record_origin,N_ ("append commit name" )), -OPT_BOOL (0 ,"ff" , &opts->allow_ff,N_ ("allow fast-forward" )), +OPT_SET_INT (0 ,"ff" , &opts->fast_forward,N_ ("allow fast-forward" ),FF_ALLOW ),OPT_BOOL (0 ,"allow-empty" , &opts->allow_empty,N_ ("preserve initially empty commits" )),OPT_BOOL (0 ,"allow-empty-message" , &opts->allow_empty_message,N_ ("allow commits with empty messages" )),OPT_BOOL (0 ,"keep-redundant-commits" , &opts->keep_redundant_commits,N_ ("keep redundant, empty commits" )),
@@ -166,7 +166,7 @@ static int run_sequencer(int argc, const char **argv, struct replay_opts *opts)"--strategy" , opts->strategy ?1 :0 ,"--strategy-option" , opts->xopts ?1 :0 ,"-x" , opts->record_origin, -"--ff" , opts->allow_ff, +"--ff" , opts->fast_forward ==FF_ALLOW ,"--rerere-autoupdate" , opts->allow_rerere_auto ==RERERE_AUTOUPDATE ,"--no-rerere-autoupdate" , opts->allow_rerere_auto ==RERERE_NOAUTOUPDATE , NULL);
@@ -177,7 +177,7 @@ static int run_sequencer(int argc, const char **argv, struct replay_opts *opts) opts->default_strategy =NULL ; } -if (opts->allow_ff) +if (opts->fast_forward ==FF_ALLOW ) verify_opt_compatible(me, "--ff", "--signoff", opts->signoff, "--no-commit", opts->no_commit,
sequencer.c +32 -21
110 lines not on this page · raw message
sequencer.h +8 -1
@@ -28,6 +28,12 @@ enum commit_msg_cleanup_mode {COMMIT_MSG_CLEANUP_ALL }; +enum ff_type { +FF_NO , +FF_ALLOW , +FF_ONLY +}; +struct replay_opts {enum replay_action action;
@@ -38,7 +44,6 @@ struct replay_opts {int record_origin;int no_commit;int signoff; -int allow_ff;int allow_rerere_auto;int allow_empty;int allow_empty_message;
@@ -50,6 +55,8 @@ struct replay_opts {int committer_date_is_author_date;int ignore_date; +enum ff_type fast_forward; +int mainline;char *gpg_sign;
t/t3404-rebase-interactive.sh +5 -0
@@ -895,6 +895,11 @@ test_expect_success 'always cherry-pick with --no-ff' ' test_must_be_empty out ' +test_expect_success 'interactive rebase prevents non-fast-forward with --ff-only' ' + git checkout primary && + test_must_fail git rebase -i --ff-only branch1 +' + test_expect_success 'set up commits with funny messages' ' git checkout -b funny A && echo >>file1 &&
t/t3409-rebase-preserve-merges.sh +4 -0
@@ -127,4 +127,8 @@ test_expect_success 'rebase -p ignores merge.log config' ' ) ' +test_expect_success 'rebase -p prevents non-fast-forward with --ff-only' ' + test_must_fail git rebase -p --ff-only main +' + test_done
t/t3420-rebase-autostash.sh +9 -0
@@ -246,6 +246,15 @@ test_expect_success "rebase: fast-forward rebase" ' git checkout feature-branch ' +test_expect_success "rebase: impossible fast-forward rebase" ' + test_config rebase.autostash true && + git reset --hard && + echo dirty >>file1 && + (git rebase --ff-only unrelated-onto-branch || true) && + grep dirty file1 && + git checkout feature-branch +' + test_expect_success "rebase: noop rebase" ' test_config rebase.autostash true && git reset --hard &&
t/t7601-merge-pull-config.sh +10 -0
@@ -183,6 +183,16 @@ test_expect_success 'pull prevents non-fast-forward with "only" in pull.ff' ' test_must_fail git pull . c3 ' +test_expect_success 'pull prevents non-fast-forward with --rebase --ff-only' ' + git reset --hard c1 && + test_must_fail git pull --rebase --ff-only . c3 +' + +test_expect_success 'pull prevents non-fast-forward with --no-rebase --ff-only' ' + git reset --hard c1 && + test_must_fail git pull --no-rebase --ff-only . c3 +' + test_expect_success 'merge c1 with c2 (ours in pull.twohead)' ' git reset --hard c1 && git config pull.twohead ours &&
Signature · 1 line
2.32.0.94.ge083fb24f6
Hi Alex
Quoted 4 lines · Alex Henrie
The warning about pulling without specifying how to reconcile divergent branches says that after setting pull.rebase to true, --ff-only can still be passed on the command line to require a fast-forward. Make that actually work.
As I understand it the motivation for this change is to have 'git -c pull.rebase=true pull --ff-only' actually fast forward. Why cant we just change pull not to rebase in that case? I've left some comments about the rebase changes below
Quoted 8 lines
[...]
builtin/rebase.c +0
-0@@ -1345,12 +1349,14 @@ int cmd_rebase(int argc, const char **argv, const char *prefix) N_("ignore changes in whitespace")), OPT_PASSTHRU_ARGV(0, "whitespace", &options.git_am_opts,
builtin/rebase.c int cmd_rebase(int argc, const char **argv, const char *prefix) · line 1354
Quoted 10 lines
builtin/rebase.c +3
-6N_("action"), N_("passed to 'git apply'"), 0), -OPT_BIT ('f' ,"force-rebase" , &options.flags, -N_ ("cherry-pick all commits, even if unchanged" ), -REBASE_FORCE ), -OPT_BIT (0 ,"no-ff" , &options.flags, -N_ ("cherry-pick all commits, even if unchanged" ), - REBASE_FORCE), +OPT_SET_INT_F ('f' ,"force-rebase" , &options.fast_forward, +N_ ("cherry-pick all commits, even if unchanged" ), + FF_NO, PARSE_OPT_NONEG),
Why does this change rebase to start rejecting --no-force-rebase? This is the sort of behavior change that deserves a mention in the commit message.
builtin/rebase.c int cmd_rebase(int argc, const char **argv, const char *prefix) · line 1356
Quoted 2 lines
builtin/rebase.c +2
-0+OPT_SET_INT (0 ,"ff" , &options.fast_forward,N_ ("allow fast-forward" ), + FF_ALLOW),
The useful option when rebasing is '--no-ff', now that will no longer appear in the output of 'git rebase -h'
builtin/rebase.c int cmd_rebase(int argc, const char **argv, const char *prefix) · line 1359
Quoted 3 lines
builtin/rebase.c +3
-0+OPT_SET_INT_F (0 ,"ff-only" , &options.fast_forward, +N_ ("abort if fast-forward is not possible" ), + FF_ONLY, PARSE_OPT_NONEG),
Is there a use for this outside of 'git pull --ff-only'? I'm far from convinced we want this new option but if we do end up adding it I think it should error out in combination with '-i' or '-x' as '-i' implies the user wants to change the existing commits and '-x' can end up changing them as well.
I think this patch addresses a valid problem but it seems to me that the approach taken pushes complexity into rebase to handle a case when pull does not need to invoke rebase in the first place.
Best Wishes
Phillip
Quoted 327 lines
builtin/rebase.c +22
-14OPT_CMDMODE (0 ,"continue" , &action,N_ ("continue" ),ACTION_CONTINUE ), OPT_CMDMODE(0, "skip", &action,@@ -1635,7 +1641,7 @@ int cmd_rebase(int argc, const char **argv, const char *prefix) allow_preemptive_ff =0 ; }if (options.committer_date_is_author_date || options.ignore_date) - options.flags |=REBASE_FORCE ; + options.fast_forward =FF_NO ;for (i =0 ; i < options.git_am_opts.nr; i++) {const char *option = options.git_am_opts.v[i], *p;@@ -1809,7 +1815,7 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)die ("cannot combine '--signoff' with " "'--preserve-merges'" );strvec_push (&options.git_am_opts,"--signoff" ); - options.flags |=REBASE_FORCE ; + options.fast_forward =FF_NO ; }if (options.type ==REBASE_PRESERVE_MERGES ) {@@ -1952,6 +1958,24 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)if (repo_read_index (the_repository) <0 )die (_ ("could not read index" )); +/* +* Check if we are already based on onto with linear history, +* in which case we could fast-forward without replacing the commits +* with new commits recreated by replaying their changes. +* +* Note that can_fast_forward() initializes merge_base, so we have to +* call it before checking allow_preemptive_ff. +*/ + allow_preemptive_ff =can_fast_forward (options.onto, options.upstream, + options.restrict_revision, + &options.orig_head, &merge_base) + && allow_preemptive_ff; + +if (!allow_preemptive_ff && options.fast_forward ==FF_ONLY ) { + ret =error_ff_impossible (); + goto cleanup; + } +if (options.autostash) {create_autostash (the_repository,state_dir_path ("autostash" , &options),DEFAULT_REFLOG_ACTION );@@ -1968,20 +1992,10 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)* everything leading up to orig_head) on top of onto. */ -/* -* Check if we are already based on onto with linear history, -* in which case we could fast-forward without replacing the commits -* with new commits recreated by replaying their changes. -* -* Note that can_fast_forward() initializes merge_base, so we have to -* call it before checking allow_preemptive_ff. -*/ -if (can_fast_forward (options.onto, options.upstream, options.restrict_revision, - &options.orig_head, &merge_base) && - allow_preemptive_ff) { +if (allow_preemptive_ff) {int flag; -if (!(options.flags &REBASE_FORCE )) { +if (options.fast_forward !=FF_NO ) {/* Lazily switch to the target branch if needed... */ if (options.switch_to) {strbuf_reset (&buf);builtin/revert.c +3
-3@@ -123,7 +123,7 @@ static int run_sequencer(int argc, const char **argv, struct replay_opts *opts)if (opts->action ==REPLAY_PICK ) {struct option cp_extra[] = {OPT_BOOL ('x' ,NULL , &opts->record_origin,N_ ("append commit name" )), -OPT_BOOL (0 ,"ff" , &opts->allow_ff,N_ ("allow fast-forward" )), +OPT_SET_INT (0 ,"ff" , &opts->fast_forward,N_ ("allow fast-forward" ),FF_ALLOW ),OPT_BOOL (0 ,"allow-empty" , &opts->allow_empty,N_ ("preserve initially empty commits" )),OPT_BOOL (0 ,"allow-empty-message" , &opts->allow_empty_message,N_ ("allow commits with empty messages" )),OPT_BOOL (0 ,"keep-redundant-commits" , &opts->keep_redundant_commits,N_ ("keep redundant, empty commits" )),@@ -166,7 +166,7 @@ static int run_sequencer(int argc, const char **argv, struct replay_opts *opts)"--strategy" , opts->strategy ?1 :0 ,"--strategy-option" , opts->xopts ?1 :0 ,"-x" , opts->record_origin, -"--ff" , opts->allow_ff, +"--ff" , opts->fast_forward ==FF_ALLOW ,"--rerere-autoupdate" , opts->allow_rerere_auto ==RERERE_AUTOUPDATE ,"--no-rerere-autoupdate" , opts->allow_rerere_auto ==RERERE_NOAUTOUPDATE , NULL);@@ -177,7 +177,7 @@ static int run_sequencer(int argc, const char **argv, struct replay_opts *opts) opts->default_strategy =NULL ; } -if (opts->allow_ff) +if (opts->fast_forward ==FF_ALLOW ) verify_opt_compatible(me, "--ff", "--signoff", opts->signoff, "--no-commit", opts->no_commit,sequencer.c +32
-21@@ -2120,18 +2120,23 @@ static int do_pick_commit(struct repository *r,return error (_ ("cannot get commit message for %s" ),oid_to_hex (&commit->object.oid)); -if (opts->allow_ff && !is_fixup (command) && - ((parent &&oideq (&parent->object.oid, &head)) || - (!parent && unborn))) { -if (is_rebase_i (opts)) -write_author_script (msg.message); - res =fast_forward_to (r, &commit->object.oid, &head, unborn, - opts); -if (res || command !=TODO_REWORD ) +if (opts->fast_forward !=FF_NO ) { +if (!is_fixup (command) && + ((parent &&oideq (&parent->object.oid, &head)) || + (!parent && unborn))) { +if (is_rebase_i (opts)) +write_author_script (msg.message); + res =fast_forward_to (r, &commit->object.oid, &head, unborn, + opts); +if (res || command !=TODO_REWORD ) + goto leave; + reword =1 ; + msg_file =NULL ; + goto fast_forward_edit; + }else if (opts->fast_forward ==FF_ONLY ) { + res =error_ff_impossible (); goto leave; - reword =1 ; - msg_file =NULL ; - goto fast_forward_edit; + } }if (parent &&parse_commit (parent) <0 )/* TRANSLATORS: The first %s will be a "todo" command like @@ -2764,7 +2769,7 @@ static int populate_opts_cb(const char *key, const char *value, void *data)else if (!strcmp (key,"options.record-origin" )) opts->record_origin =git_config_bool_or_int (key, value, &error_flag);else if (!strcmp (key,"options.allow-ff" )) - opts->allow_ff =git_config_bool_or_int (key, value, &error_flag); + opts->fast_forward =git_config_bool_or_int (key, value, &error_flag) ?FF_ALLOW :FF_NO ;else if (!strcmp (key,"options.mainline" )) opts->mainline =git_config_int (key, value);else if (!strcmp (key,"options.strategy" ))@@ -2853,17 +2858,17 @@ static int read_populate_opts(struct replay_opts *opts) opts->quiet =1 ;if (file_exists (rebase_path_signoff ())) { - opts->allow_ff =0 ; + opts->fast_forward =FF_NO ; opts->signoff =1 ; }if (file_exists (rebase_path_cdate_is_adate ())) { - opts->allow_ff =0 ; + opts->fast_forward =FF_NO ; opts->committer_date_is_author_date =1 ; }if (file_exists (rebase_path_ignore_date ())) { - opts->allow_ff =0 ; + opts->fast_forward =FF_NO ; opts->ignore_date =1 ; }@@ -3320,7 +3325,7 @@ static int save_opts(struct replay_opts *opts)if (opts->record_origin) res |=git_config_set_in_file_gently (opts_file,"options.record-origin" ,"true" ); -if (opts->allow_ff) +if (opts->fast_forward ==FF_ALLOW ) res |=git_config_set_in_file_gently (opts_file,"options.allow-ff" ,"true" );if (opts->mainline) {@@ -3849,9 +3854,9 @@ static int do_merge(struct repository *r,* If HEAD is not identical to the first parent of the original merge * commit, we cannot fast-forward. */ - can_fast_forward = opts->allow_ff && commit && commit->parents && -oideq (&commit->parents->item->object.oid, - &head_commit->object.oid); + can_fast_forward = opts->fast_forward !=FF_NO && commit && + commit->parents &&oideq (&commit->parents->item->object.oid, + &head_commit->object.oid);/* * If any merge head is different from the original one, we cannot @@ -3885,6 +3890,11 @@ static int do_merge(struct repository *r, goto leave_merge; } +if (opts->fast_forward ==FF_ONLY && !can_fast_forward) { + ret =error_ff_impossible (); + goto leave_merge; + } +if (strategy || to_merge->next) {/* Octopus merge */ struct child_process cmd =CHILD_PROCESS_INIT ;@@ -4276,7 +4286,7 @@ static int pick_commits(struct repository *r,/* Note that 0 for 3rd parameter of setenv means set only if not set */ setenv (GIT_REFLOG_ACTION ,action_name (opts),0 ); prev_reflog_action =xstrdup (getenv (GIT_REFLOG_ACTION )); -if (opts->allow_ff) +if (opts->fast_forward !=FF_NO ) assert(!(opts->signoff || opts->no_commit || opts->record_origin || should_edit(opts) || opts->committer_date_is_author_date ||@@ -5646,7 +5656,8 @@ int complete_action(struct repository *r, struct replay_opts *opts, unsigned flaBUG ("invalid todo list after expanding IDs:\n%s" , new_todo.buf.buf); -if (opts->allow_ff &&skip_unnecessary_picks (r, &new_todo, &oid)) { +if (opts->fast_forward !=FF_NO + &&skip_unnecessary_picks (r, &new_todo, &oid)) {todo_list_release (&new_todo);return error (_ ("could not skip unnecessary pick commands" )); }sequencer.h +8
-1@@ -28,6 +28,12 @@ enum commit_msg_cleanup_mode {COMMIT_MSG_CLEANUP_ALL }; +enum ff_type { +FF_NO , +FF_ALLOW , +FF_ONLY +}; +struct replay_opts {enum replay_action action;@@ -38,7 +44,6 @@ struct replay_opts {int record_origin;int no_commit;int signoff; -int allow_ff;int allow_rerere_auto;int allow_empty;int allow_empty_message;@@ -50,6 +55,8 @@ struct replay_opts {int committer_date_is_author_date;int ignore_date; +enum ff_type fast_forward; +int mainline;char *gpg_sign;t/t3404-rebase-interactive.sh +5
-0@@ -895,6 +895,11 @@ test_expect_success 'always cherry-pick with --no-ff' ' test_must_be_empty out ' +test_expect_success 'interactive rebase prevents non-fast-forward with --ff-only' ' + git checkout primary && + test_must_fail git rebase -i --ff-only branch1 +' + test_expect_success 'set up commits with funny messages' ' git checkout -b funny A && echo >>file1 &&t/t3409-rebase-preserve-merges.sh +4
-0@@ -127,4 +127,8 @@ test_expect_success 'rebase -p ignores merge.log config' ' ) ' +test_expect_success 'rebase -p prevents non-fast-forward with --ff-only' ' + test_must_fail git rebase -p --ff-only main +' + test_donet/t3420-rebase-autostash.sh +9
-0@@ -246,6 +246,15 @@ test_expect_success "rebase: fast-forward rebase" ' git checkout feature-branch ' +test_expect_success "rebase: impossible fast-forward rebase" ' + test_config rebase.autostash true && + git reset --hard && + echo dirty >>file1 && + (git rebase --ff-only unrelated-onto-branch || true) && + grep dirty file1 && + git checkout feature-branch +' + test_expect_success "rebase: noop rebase" ' test_config rebase.autostash true && git reset --hard &&t/t7601-merge-pull-config.sh +10
-0@@ -183,6 +183,16 @@ test_expect_success 'pull prevents non-fast-forward with "only" in pull.ff' ' test_must_fail git pull . c3 ' +test_expect_success 'pull prevents non-fast-forward with --rebase --ff-only' ' + git reset --hard c1 && + test_must_fail git pull --rebase --ff-only . c3 +' + +test_expect_success 'pull prevents non-fast-forward with --no-rebase --ff-only' ' + git reset --hard c1 && + test_must_fail git pull --no-rebase --ff-only . c3 +' + test_expect_success 'merge c1 with c2 (ours in pull.twohead)' ' git reset --hard c1 && git config pull.twohead ours &&
Quoted 10 lines · Phillip Wood
As I understand it the motivation for this change is to have 'git -c pull.rebase=true pull --ff-only' actually fast forward. Why cant we just change pull not to rebase in that case?
...
Is there a use for this outside of 'git pull --ff-only'? I'm far from convinced we want this new option but if we do end up adding it I think it should error out in combination with '-i' or '-x' as '-i' implies the user wants to change the existing commits and '-x' can end up changing them as well.
Quoted 3 lines
I think this patch addresses a valid problem but it seems to me that the approach taken pushes complexity into rebase to handle a case when pull does not need to invoke rebase in the first place.
I share the sentiment, but my conclusion would be different.
Even though we explain that "pull" is _like_ "fetch" followed by "merge" (or "rebase"), at the conceptual level, "pull --ff-only" should not have to invoke merge or rebase backend. If the branch fast-fowards to the fetched tip, "pull" should be able to just update the branch and check it out, and if it doesn't, "pull" should just be able to fail.
Similarly, "pull --ff" (i.e. fast-forwading allowed) should be able to just update the branch and check it out when the current tip of the branch can be fast-forwarded to the fetched tip.
But as you said, pull.rebase=interactive will break such a clean separation of concerns. You can leave "pull" oblivious of what "rebase -i" wants to do when seeing a fast-forwardable history by teaching "rebase" (and "merge") backend to take "--ff-only", "--ff", and "--no-ff" options and having "pull" pass them through.
We can teach "pull" that certain backends (namely "rebase -i" in this case) want to handle "ff logic" [*] themselves, and other backends (i.e. "rebase" and "merge") do not mind if "pull" handles "ff logic" for them, but that will break the abstraction (e.g. do we really want to teach "pull" that "rebase -i" wants to rewrite all the commits even when the history fast-forwards?) and will become a source of duplicated logic.
Another thing to worry about are hooks. post-rebase or post-merge operations would want to be carried out even when the history would fast-forward, and making "pull" to perform the fast-forwarding and know which hooks should be called with what parameter so that we could pretend as if the "merge" or "rebase" backend was indeed ran, breaks the abstraction.
So, even though I wish that the world was simpler and we could handle "ff logic" inside "pull", I am not sure if it is a realistic wish.
[Footnote]
* By "ff logic", I am referring to what should happen in the 3x2=6 matrix when one of ("--ff", "--ff-only", or "--no-ff") is given and the history (does or does not) fast-forward.
Quoted 16 lines · Junio C Hamano
Quoted 10 lines · Phillip Wood
As I understand it the motivation for this change is to have 'git -c pull.rebase=true pull --ff-only' actually fast forward. Why cant we just change pull not to rebase in that case?
...
Is there a use for this outside of 'git pull --ff-only'? I'm far from convinced we want this new option but if we do end up adding it I think it should error out in combination with '-i' or '-x' as '-i' implies the user wants to change the existing commits and '-x' can end up changing them as well.Quoted 3 lines
I think this patch addresses a valid problem but it seems to me that the approach taken pushes complexity into rebase to handle a case when pull does not need to invoke rebase in the first place.
Quoted 5 lines
I share the sentiment, but my conclusion would be different.
Even though we explain that "pull" is _like_ "fetch" followed by "merge" (or "rebase"), at the conceptual level, "pull --ff-only" should not have to invoke merge or rebase backend.
Indeed. I'm about to send a patch series that adds the git fast-forward command, so git pull doesn't even have to call either of those.
This cleanly separates the logic, except --ff-only remains purely for git merge, and instead there's a new:
git -c pull.mode=fast-forward pull
Now it's 100% clear what these three do:
git -c pull.mode=fast-forward pull
git -c pull.mode=merge pull
git -c pull.mode=rebase pull
Signature · 1 line
Felipe Contreras
Hi Junio
Quoted 29 lines · Junio C Hamano
Quoted 10 lines · Phillip Wood
As I understand it the motivation for this change is to have 'git -c pull.rebase=true pull --ff-only' actually fast forward. Why cant we just change pull not to rebase in that case?
...
Is there a use for this outside of 'git pull --ff-only'? I'm far from convinced we want this new option but if we do end up adding it I think it should error out in combination with '-i' or '-x' as '-i' implies the user wants to change the existing commits and '-x' can end up changing them as well.Quoted 3 lines
I think this patch addresses a valid problem but it seems to me that the approach taken pushes complexity into rebase to handle a case when pull does not need to invoke rebase in the first place.
I share the sentiment, but my conclusion would be different.
Even though we explain that "pull" is _like_ "fetch" followed by "merge" (or "rebase"), at the conceptual level, "pull --ff-only" should not have to invoke merge or rebase backend. If the branch fast-fowards to the fetched tip, "pull" should be able to just update the branch and check it out, and if it doesn't, "pull" should just be able to fail.
Similarly, "pull --ff" (i.e. fast-forwading allowed) should be able to just update the branch and check it out when the current tip of the branch can be fast-forwarded to the fetched tip.
Quoted 5 lines
But as you said, pull.rebase=interactive will break such a clean separation of concerns. You can leave "pull" oblivious of what "rebase -i" wants to do when seeing a fast-forwardable history by teaching "rebase" (and "merge") backend to take "--ff-only", "--ff", and "--no-ff" options and having "pull" pass them through.
My main concern with the new rebase option was about a user invoking 'git rebase -i --ff-only' directly.
If a user has pull.rebase=interactive and runs 'git pull --ff-only' then I'm not clear what they expect to happen. Assuming we can fast-forward would they expect pull to run 'rebase -i' which would open their editor with the todo list or would they expect that '--ff-only' means "I just want to fast-forward, I don't want to run 'rebase -i'". If it is the latter then we can just invoke 'git merge --ff-only' (so long as we don't mind running the post-merge hook in this case) and not worry about adding more complexity to 'git rebase'
The relevant section of the pull man page only talks about merging in relation to --ff-only
--ff, --no-ff, --ff-only
Specifies how a merge is handled when the merged-in history is already a descendant of the current history. --ff is the default unless merging an annotated (and possibly signed) tag that is not stored in its natural place in the refs/tags/ hierarchy, in which case --no-ff is assumed.
With --ff, when possible resolve the merge as a fast-forward (only update the branch pointer to match the merged branch; do not create a merge commit). When not possible (when the merged-in history is not a descendant of the current history), create a merge commit.
With --no-ff, create a merge commit in all cases, even when the merge could instead be resolved as a fast-forward.
With --ff-only, resolve the merge as a fast-forward when possible. When not possible, refuse to merge and exit with a non-zero status.
Quoted 9 lines
We can teach "pull" that certain backends (namely "rebase -i" in this case) want to handle "ff logic" [*] themselves, and other backends (i.e. "rebase" and "merge") do not mind if "pull" handles "ff logic" for them, but that will break the abstraction (e.g. do we really want to teach "pull" that "rebase -i" wants to rewrite all the commits even when the history fast-forwards?) and will become a source of duplicated logic.
Another thing to worry about are hooks. post-rebase
There is no post-rebase hook. There is the post-rewrite hook, I haven't checked if we invoke it with no input of skip it entirely when we fast-forward.
Quoted 10 lines
or post-merge
operations would want to be carried out even when the history would fast-forward, and making "pull" to perform the fast-forwarding and know which hooks should be called with what parameter so that we could pretend as if the "merge" or "rebase" backend was indeed ran, breaks the abstraction.So, even though I wish that the world was simpler and we could handle "ff logic" inside "pull", I am not sure if it is a realistic wish.
I think if we decide that 'pull --ff-only' always implies merging then the world stays fairly simple. On the other hand if we want to somehow combine rebasing with --ff-only it will be more complicated. If we go for the latter then unless someone comes up with a good use for 'rebase --ff-only' in another context I would prefer the new rebase option to be marked with PARSE_OPT_HIDDEN and that we also avoid making incidental changes the existing rebase options.
Best Wishes
Phillip
Quoted 7 lines
[Footnote]
* By "ff logic", I am referring to what should happen in the 3x2=6 matrix when one of ("--ff", "--ff-only", or "--no-ff") is given and the history (does or does not) fast-forward.
Quoted 5 lines · Phillip Wood
On 05/07/2021 10:58, Junio C Hamano wrote:
My main concern with the new rebase option was about a user invoking 'git rebase -i --ff-only' directly.
Quoted 8 lines
If a user has pull.rebase=interactive and runs 'git pull --ff-only' then I'm not clear what they expect to happen. Assuming we can fast-forward would they expect pull to run 'rebase -i' which would open their editor with the todo list or would they expect that '--ff-only' means "I just want to fast-forward, I don't want to run 'rebase -i'". If it is the latter then we can just invoke 'git merge --ff-only' (so long as we don't mind running the post-merge hook in this case) and not worry about adding more complexity to 'git rebase'
Once again my suggestion is to keep these as orthogonal, then everything becomes clear:
git -c pull.mode=ff-only -c pull.rebase=interactive pull
This is just a fast-forward merge (git merge --ff-only).
git -c pull.mode=ff-only -c pull.rebase=interactive pull --rebase
This is an interactive rebase (--ff-only is ignored).
git -c pull.mode=ff-only -c pull.rebase=interactive pull --merge
This is a real merge (both --ff-only and --rebase=interactive are ignored).
git -c pull.mode=ff-only -c pull.rebase=interactive pull --merge --ff-only
This is a --ff-only merge.
Quoted 2 lines
The relevant section of the pull man page only talks about merging in relation to --ff-only
And my suggestion is that it should stay that way.
Quoted 7 lines
Quoted 7 lines
or post-merge
operations would want to be carried out even when the history would fast-forward, and making "pull" to perform the fast-forwarding and know which hooks should be called with what parameter so that we could pretend as if the "merge" or "rebase" backend was indeed ran, breaks the abstraction.
Quoted 6 lines
Quoted 3 lines
So, even though I wish that the world was simpler and we could handle "ff logic" inside "pull", I am not sure if it is a realistic wish.
I think if we decide that 'pull --ff-only' always implies merging then the world stays fairly simple.
Indeed, which is my suggestion.
Quoted 6 lines
On the other hand if we want to somehow
combine rebasing with --ff-only it will be more complicated. If we go for the latter then unless someone comes up with a good use for 'rebase --ff-only' in another context I would prefer the new rebase option to be marked withPARSE_OPT_HIDDENand that we also avoid making incidental changes the existing rebase options.
Once again, we cannot do that, because then this will be broken:
git -c pull.ff=only pull --rebase
Signature · 1 line
Felipe Contreras
Quoted 9 lines · Phillip Wood
Hi Alex
Quoted 4 lines · Alex Henrie
The warning about pulling without specifying how to reconcile divergent branches says that after setting pull.rebase to true, --ff-only can still be passed on the command line to require a fast-forward. Make that actually work.
As I understand it the motivation for this change is to have 'git -c pull.rebase=true pull --ff-only' actually fast forward. Why cant we just change pull not to rebase in that case?
Looking at origin/seen:builtin/pull.c we already check if we can fast-forward and unconditionally merge in that case irrespective of any '--rebase' option or pull.rebase config. It should be simple for pull to error out if '--ff-only' is given and we cannot fast-forward.
Best Wishes
Phillip
Quoted 372 lines
I've left some comments about the rebase changes below
Quoted 9 lines
[...]
builtin/rebase.c +0
-0@@ -1345,12 +1349,14 @@ int cmd_rebase(int argc, const char **argv, const char *prefix) N_("ignore changes in whitespace")), OPT_PASSTHRU_ARGV(0, "whitespace", &options.git_am_opts,builtin/rebase.c int cmd_rebase(int argc, const char **argv, · line 1355
Quoted 10 lines
builtin/rebase.c +3
-6N_("action"), N_("passed to 'git apply'"), 0), - OPT_BIT('f', "force-rebase", &options.flags, - N_("cherry-pick all commits, even if unchanged"), - REBASE_FORCE), - OPT_BIT(0, "no-ff", &options.flags, - N_("cherry-pick all commits, even if unchanged"), - REBASE_FORCE), + OPT_SET_INT_F('f', "force-rebase", &options.fast_forward, + N_("cherry-pick all commits, even if unchanged"), + FF_NO, PARSE_OPT_NONEG),Why does this change rebase to start rejecting --no-force-rebase? This is the sort of behavior change that deserves a mention in the commit message.
builtin/rebase.c int cmd_rebase(int argc, const char **argv, · line 1358
Quoted 3 lines
builtin/rebase.c +2
-0+ OPT_SET_INT(0, "ff", &options.fast_forward, N_("allow fast-forward"), + FF_ALLOW),The useful option when rebasing is '--no-ff', now that will no longer appear in the output of 'git rebase -h'
builtin/rebase.c int cmd_rebase(int argc, const char **argv, const char *prefix) · line 1359
Quoted 3 lines
builtin/rebase.c +3
-0+ OPT_SET_INT_F(0, "ff-only", &options.fast_forward, + N_("abort if fast-forward is not possible"), + FF_ONLY, PARSE_OPT_NONEG),Is there a use for this outside of 'git pull --ff-only'? I'm far from convinced we want this new option but if we do end up adding it I think it should error out in combination with '-i' or '-x' as '-i' implies the user wants to change the existing commits and '-x' can end up changing them as well.
I think this patch addresses a valid problem but it seems to me that the approach taken pushes complexity into rebase to handle a case when pull does not need to invoke rebase in the first place.
Best Wishes
Phillip
Quoted 330 lines
builtin/rebase.c +0
-0OPT_CMDMODE(0, "continue", &action, N_("continue"),
ACTION_CONTINUE),
OPT_CMDMODE(0, "skip", &action,builtin/rebase.c +1
-1@@ -1635,7 +1641,7 @@ int cmd_rebase(int argc, const char **argv, const char *prefix) allow_preemptive_ff = 0; } if (options.committer_date_is_author_date || options.ignore_date) - options.flags |= REBASE_FORCE; + options.fast_forward = FF_NO; for (i = 0; i < options.git_am_opts.nr; i++) { const char *option = options.git_am_opts.v[i], *p;@@ -1809,7 +1815,7 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
die("cannot combine '--signoff' with " "'--preserve-merges'");strvec_push(&options.git_am_opts, "--signoff"); - options.flags |=REBASE_FORCE;
+ options.fast_forward =FF_NO;
}
if (options.type ==REBASE_PRESERVE_MERGES) {builtin/rebase.c +6
-0@@ -1952,6 +1958,24 @@ int cmd_rebase(int argc, const char **argv, const char *prefix) if (repo_read_index(the_repository) < 0) die(_("could not read index")); + /* +* Check if we are already based on onto with linear history, +* in which case we could fast-forward without replacing the commits +* with new commits recreated by replaying their changes. +* +* Note that can_fast_forward() initializes merge_base, so we have to
+ * call it before checkingallow_preemptive_ff. + */
+allow_preemptive_ff= can_fast_forward(options.onto, options.upstream,
+ options.restrict_revision, + &options.orig_head,&merge_base) + &&allow_preemptive_ff;builtin/rebase.c +6
-0+ + if (!allow_preemptive_ff && options.fast_forward == FF_ONLY) { + ret = error_ff_impossible(); + goto cleanup; + } +if (options.autostash) {
create_autostash(the_repository, state_dir_path("autostash", &options), DEFAULT_REFLOG_ACTION);builtin/rebase.c +0
-6@@ -1968,20 +1992,10 @@ int cmd_rebase(int argc, const char **argv,const char *prefix) * everything leading up to orig_head) on top of onto. */ - /* -* Check if we are already based on onto with linear history, -* in which case we could fast-forward without replacing the commits -* with new commits recreated by replaying their changes. -* -* Note that can_fast_forward() initializes merge_base, so we have to
- * call it before checkingallow_preemptive_ff.
- */
- if (can_fast_forward(options.onto, options.upstream, options.restrict_revision,
- &options.orig_head,&merge_base) &&
-allow_preemptive_ff) {
+ if (allow_preemptive_ff) {
int flag;
- if (!(options.flags &REBASE_FORCE)) {
+ if (options.fast_forward !=FF_NO) {
/* Lazily switch to the target branch if needed... */ if (options.switch_to) {strbuf_reset(&buf);builtin/revert.c +1
-1@@ -123,7 +123,7 @@ static int run_sequencer(int argc, const char **argv, struct replay_opts *opts) if (opts->action == REPLAY_PICK) { struct option cp_extra[] = { OPT_BOOL('x', NULL, &opts->record_origin, N_("append commit name")), - OPT_BOOL(0, "ff", &opts->allow_ff, N_("allow fast-forward")), + OPT_SET_INT(0, "ff", &opts->fast_forward, N_("allow fast-forward"), FF_ALLOW),
OPT_BOOL(0, "allow-empty", &opts->allow_empty, N_("preserve initially empty commits")),OPT_BOOL(0, "allow-empty-message", &opts->allow_empty_message, N_("allow commits with empty messages")),OPT_BOOL(0, "keep-redundant-commits", &opts->keep_redundant_commits, N_("keep redundant, empty commits")),builtin/revert.c +1
-1@@ -166,7 +166,7 @@ static int run_sequencer(int argc, const char **argv, struct replay_opts *opts) "--strategy", opts->strategy ? 1 : 0, "--strategy-option", opts->xopts ? 1 : 0, "-x", opts->record_origin, - "--ff", opts->allow_ff, + "--ff", opts->fast_forward == FF_ALLOW, "--rerere-autoupdate", opts->allow_rerere_auto == RERERE_AUTOUPDATE, "--no-rerere-autoupdate", opts->allow_rerere_auto == RERERE_NOAUTOUPDATE,NULL);
builtin/revert.c +1
-1@@ -177,7 +177,7 @@ static int run_sequencer(int argc, const char **argv, struct replay_opts *opts) opts->default_strategy = NULL; } - if (opts->allow_ff) + if (opts->fast_forward == FF_ALLOW) verify_opt_compatible(me, "--ff", "--signoff", opts->signoff, "--no-commit", opts->no_commit,sequencer.c +17
-12@@ -2120,18 +2120,23 @@ static int do_pick_commit(struct repository *r, return error(_("cannot get commit message for %s"), oid_to_hex(&commit->object.oid)); - if (opts->allow_ff && !is_fixup(command) && - ((parent && oideq(&parent->object.oid, &head)) || - (!parent && unborn))) { - if (is_rebase_i(opts)) - write_author_script(msg.message); - res = fast_forward_to(r, &commit->object.oid, &head, unborn, - opts); - if (res || command != TODO_REWORD) + if (opts->fast_forward != FF_NO) { + if (!is_fixup(command) && + ((parent && oideq(&parent->object.oid, &head)) || + (!parent && unborn))) { + if (is_rebase_i(opts)) + write_author_script(msg.message); + res = fast_forward_to(r, &commit->object.oid, &head, unborn, + opts); + if (res || command != TODO_REWORD) + goto leave; + reword = 1; + msg_file = NULL; + goto fast_forward_edit; + } else if (opts->fast_forward == FF_ONLY) { + res = error_ff_impossible(); goto leave; - reword = 1; - msg_file = NULL; - goto fast_forward_edit; + } } if (parent && parse_commit(parent) < 0) /* TRANSLATORS: The first %s will be a "todo" command like@@ -2764,7 +2769,7 @@ static int populate_opts_cb(const char *key, const char *value, void *data) else if (!strcmp(key, "options.record-origin")) opts->record_origin = git_config_bool_or_int(key, value, &error_flag); else if (!strcmp(key, "options.allow-ff")) - opts->allow_ff = git_config_bool_or_int(key, value, &error_flag); + opts->fast_forward = git_config_bool_or_int(key, value, &error_flag) ?FF_ALLOW :FF_NO ;else if (!strcmp(key, "options.mainline"))
opts->mainline=git_config_int(key, value); else if (!strcmp(key, "options.strategy"))sequencer.c +13
-8@@ -2853,17 +2858,17 @@ static int read_populate_opts(struct replay_opts *opts) opts->quiet = 1; if (file_exists(rebase_path_signoff())) { - opts->allow_ff = 0; + opts->fast_forward = FF_NO; opts->signoff = 1; } if (file_exists(rebase_path_cdate_is_adate())) { - opts->allow_ff = 0; + opts->fast_forward = FF_NO; opts->committer_date_is_author_date = 1; } if (file_exists(rebase_path_ignore_date())) { - opts->allow_ff = 0; + opts->fast_forward = FF_NO; opts->ignore_date = 1; }@@ -3320,7 +3325,7 @@ static int save_opts(struct replay_opts *opts) if (opts->record_origin) res |= git_config_set_in_file_gently(opts_file, "options.record-origin", "true"); - if (opts->allow_ff) + if (opts->fast_forward == FF_ALLOW) res |= git_config_set_in_file_gently(opts_file, "options.allow-ff", "true"); if (opts->mainline) {@@ -3849,9 +3854,9 @@ static int do_merge(struct repository *r,* If HEAD is not identical to the first parent of the original merge * commit, we cannot fast-forward. */ - can_fast_forward = opts->allow_ff && commit && commit->parents && - oideq(&commit->parents->item->object.oid, - &head_commit->object.oid); + can_fast_forward = opts->fast_forward != FF_NO && commit && + commit->parents && oideq(&commit->parents->item->object.oid, + &head_commit->object.oid); /** If any merge head is different from the original one, we cannot @@ -3885,6 +3890,11 @@ static int do_merge(struct repository *r, goto leave_merge; } + if (opts->fast_forward == FF_ONLY && !can_fast_forward) { + ret = error_ff_impossible(); + goto leave_merge; + } + if (strategy || to_merge->next) { /* Octopus merge */ struct child_process cmd = CHILD_PROCESS_INIT;@@ -4276,7 +4286,7 @@ static int pick_commits(struct repository *r, /* Note that 0 for 3rd parameter of setenv means set only if not set */ setenv(GIT_REFLOG_ACTION, action_name(opts), 0); prev_reflog_action = xstrdup(getenv(GIT_REFLOG_ACTION)); - if (opts->allow_ff) + if (opts->fast_forward != FF_NO)assert(!(opts->signoff ||
opts->no_commit||opts->record_origin||should_edit(opts)||opts->committer_date_is_author_date||sequencer.c +0
-0@@ -5646,7 +5656,8 @@ int complete_action(struct repository *r, struct
replay_opts*opts, unsigned fla
BUG("invalid todo list after expanding IDs:\n%s", new_todo.buf.buf);
- if (opts->allow_ff&&skip_unnecessary_picks(r, &new_todo, &oid)) { + if (opts->fast_forward!=FF_NO
+ &&skip_unnecessary_picks(r, &new_todo, &oid)) {todo_list_release(&new_todo);
returnerror(_("could not skip unnecessary pick commands")); }sequencer.h +0
-0@@ -28,6 +28,12 @@ enum commit_msg_cleanup_mode {
COMMIT_MSG_CLEANUP_ALL
};sequencer.h +6
-0+enum ff_type { + FF_NO, + FF_ALLOW, + FF_ONLY +}; +struct
replay_opts{
enumreplay_actionaction;sequencer.h +2
-1@@ -38,7 +44,6 @@ struct replay_opts { int record_origin; int no_commit; int signoff; - int allow_ff; int allow_rerere_auto; int allow_empty; int allow_empty_message;@@ -50,6 +55,8 @@ struct replay_opts { int committer_date_is_author_date; int ignore_date; + enum ff_type fast_forward; + int mainline; char *gpg_sign;t/t3404-rebase-interactive.sh +0
-1@@ -895,6 +895,11 @@ test_expect_success 'always cherry-pick with --no-ff' '
test_must_be_emptyout
'
+test_expect_success 'interactive rebase prevents non-fast-forward with --ff-only' '
+ git checkout primary &&
+test_must_failgit rebase -i --ff-only branch1
+'
+
test_expect_success'set up commits with funny messages' ' git checkout -b funny A &&
echo >>file1 &&t/t3409-rebase-preserve-merges.sh +0
-0@@ -127,4 +127,8 @@ test_expect_success 'rebase -p ignores merge.logconfig' '
)
't/t3409-rebase-preserve-merges.sh +4
-1+test_expect_success 'rebase -p prevents non-fast-forward with --ff-only' ' + test_must_fail git rebase -p --ff-only main +' +
test_donet/t3420-rebase-autostash.sh +0
-0@@ -246,6 +246,15 @@ test_expect_success "rebase: fast-forward rebase" 'git checkout feature-branch
't/t3420-rebase-autostash.sh +9
-0+test_expect_success "rebase: impossible fast-forward rebase" ' + test_config rebase.autostash true && + git reset --hard && + echo dirty >>file1 && + (git rebase --ff-only unrelated-onto-branch || true) && + grep dirty file1 && + git checkout feature-branch +' +
test_expect_success"rebase: noop rebase" '
test_configrebase.autostash true &&
git reset --hard &&t/t7601-merge-pull-config.sh +0
-0@@ -183,6 +183,16 @@ test_expect_success 'pull preventsnon-fast-forward with "only" in pull.ff' '
test_must_failgit pull . c3
't/t7601-merge-pull-config.sh +10
-2+test_expect_success 'pull prevents non-fast-forward with --rebase --ff-only' ' + git reset --hard c1 && + test_must_fail git pull --rebase --ff-only . c3 +' + +test_expect_success 'pull prevents non-fast-forward with --no-rebase --ff-only' ' + git reset --hard c1 && + test_must_fail git pull --no-rebase --ff-only . c3 +' +
test_expect_success'merge c1 with c2 (ours in pull.twohead)' ' git reset --hard c1 &&
git config pull.twohead ours &&
Quoted 4 lines · Phillip Wood
Looking at origin/seen:builtin/pull.c we already check if we can fast-forward and unconditionally merge in that case irrespective of any '--rebase' option or pull.rebase config. It should be simple for pull to error out if '--ff-only' is given and we cannot fast-forward.
Excellent.
Even though teaching even more special case on the "git pull" side makes me feel somewhat dirty, but I think it would be a small price to pay, and the end result would save an useless fork whose sole purpose is to make the integration step after fetch fail when "pull" can easily tell, as you said, that it ought to fail, so overall it would probably be a net win.
Thanks.
Quoted 7 lines · Junio C Hamano
Quoted 4 lines · Phillip Wood
Looking at origin/seen:builtin/pull.c we already check if we can fast-forward and unconditionally merge in that case irrespective of any '--rebase' option or pull.rebase config. It should be simple for pull to error out if '--ff-only' is given and we cannot fast-forward.
Quoted 8 lines
Excellent.
Even though teaching even more special case on the "git pull" side makes me feel somewhat dirty, but I think it would be a small price to pay, and the end result would save an useless fork whose sole purpose is to make the integration step after fetch fail when "pull" can easily tell, as you said, that it ought to fail, so overall it would probably be a net win.
A tangent after thinking a bit more.
I do not think "pull.rebase=interactive" affects the "ff logic" at all. Rebasing integration rebuilds _your_ commits on the current branch on top of the tip of _their_ history, and if their history is a descendant of your history (i.e. the history fast-forwards), by definition, you do not have anything you need to rebuild on top of theirs, whether with the opportunity to make tweaks via "rebase -i" or without.
This observation does not change the conclusion at all, but I should have spoken after thinking X-<.
Thanks.
Quoted 14 lines · Phillip Wood
Quoted 12 lines · Alex Henrie
index
12f093121d..b88f0cbcca100644builtin/rebase.c +0
-5@@ -1345,12 +1349,14 @@ int cmd_rebase(int argc, const char **argv, const char *prefix) N_("ignore changes in whitespace")),OPT_PASSTHRU_ARGV (0 ,"whitespace" , &options.git_am_opts, N_("action"), N_("passed to 'git apply'"), 0), -OPT_BIT ('f' ,"force-rebase" , &options.flags, -N_ ("cherry-pick all commits, even if unchanged" ), -REBASE_FORCE ), - OPT_BIT(0, "no-ff", &options.flags, - N_("cherry-pick all commits, even if unchanged"),
Quoted 8 lines
builtin/rebase.c int cmd_rebase(int argc, const char **argv, const char *prefix) · line 1354
Quoted 4 lines
builtin/rebase.c +3
-1- REBASE_FORCE), +OPT_SET_INT_F ('f' ,"force-rebase" , &options.fast_forward, +N_ ("cherry-pick all commits, even if unchanged" ), + FF_NO, PARSE_OPT_NONEG),Why does this change rebase to start rejecting --no-force-rebase? This is the sort of behavior change that deserves a mention in the commit message.
That was accidental, sorry. I copied and pasted option code from another place without paying attention to the PARSE_OPT_NONEG.
Quoted 5 lines
builtin/rebase.c int cmd_rebase(int argc, const char **argv, const char *prefix) · line 1356
Quoted 2 lines
builtin/rebase.c +2
-0+OPT_SET_INT (0 ,"ff" , &options.fast_forward,N_ ("allow fast-forward" ), + FF_ALLOW),The useful option when rebasing is '--no-ff', now that will no longer appear in the output of 'git rebase -h'
Yeah, that's a good point.
Quoted 10 lines · Ævar Arnfjörð Bjarmason
builtin/rebase.c int cmd_rebase(int argc, const char **argv, const char *prefix) · line 1361
Quoted 5 lines · Alex Henrie
builtin/rebase.c +5
-0+int error_ff_impossible (void ) +{ +error (_ ("Not possible to fast-forward, aborting." )); +return -1 ; +}Here's one, the idiom is just "return error", i.e it itself returns -1.
That would indeed be simpler; thanks for pointing that out.
Quoted 10 lines
FWIW I'd consider doing:
/* earlier, static scope */ static const char error_ff_impossible = N_("Not possible..."); /* later, function scope */ return error(error_ff_impossible);It's a small difference, but for translators who use the jump-to-source while translating not having the indirection helps, and in this case it's just used 3 times...
Wouldn't jump-to-source take the user to the English text in advice.c either way? How does putting it in a static variable help?
Quoted 11 lines
builtin/rebase.c static int populate_opts_cb(const char *key, const char *value, void *data) · line 2772
Quoted 9 lines
[...]
if (parent && parse_commit(parent) < 0) /* TRANSLATORS: The first %s will be a "todo" command likebuiltin/rebase.c +1
-1@@ -2764,7 +2769,7 @@ static int populate_opts_cb(const char *key, const char *value, void *data)else if (!strcmp (key,"options.record-origin" )) opts->record_origin =git_config_bool_or_int (key, value, &error_flag);else if (!strcmp (key,"options.allow-ff" )) - opts->allow_ff =git_config_bool_or_int (key, value, &error_flag); + opts->fast_forward =git_config_bool_or_int (key, value, &error_flag) ?FF_ALLOW :FF_NO ;Since we're on nits, we try to wrap at 80 characters.
Thanks, I didn't know what the exact cutoff was.
Quoted 8 lines
builtin/rebase.c static int populate_opts_cb(const char *key, const char *value, void *data)
Quoted 5 lines
builtin/rebase.c +5
-0+test_expect_success "rebase: impossible fast-forward rebase" ' + test_config rebase.autostash true && + git reset --hard && + echo dirty >>file1 && + (git rebase --ff-only unrelated-onto-branch || true) &&Never "||" git commands, better as
test_might_fail. We don't want to hide segfaults.
Also thanks for the advice here.
Quoted 8 lines · Junio C Hamano
Quoted 4 lines · Phillip Wood
Looking at origin/seen:builtin/pull.c we already check if we can fast-forward and unconditionally merge in that case irrespective of any '--rebase' option or pull.rebase config. It should be simple for pull to error out if '--ff-only' is given and we cannot fast-forward.
Quoted 8 lines
Excellent.
Even though teaching even more special case on the "git pull" side makes me feel somewhat dirty, but I think it would be a small price to pay, and the end result would save an useless fork whose sole purpose is to make the integration step after fetch fail when "pull" can easily tell, as you said, that it ought to fail, so overall it would probably be a net win.
Okay, so it sounds like I should just scrap this patch and try again, after "pull: cleanup autostash check" is in master, with a patch that only modifies git pull and not git rebase. (Unless someone more experienced wants to take over, which would be fine by me.)
Thanks anyway to Phillip and Ævar: Your feedback will help me write better patches in the future.
-Alex
Quoted 21 lines · Alex Henrie
Quoted 10 lines · Ævar Arnfjörð Bjarmason
advice.c void list_config_advices(struct string_list *list, const char *prefix) · line 253
Quoted 5 lines · Alex Henrie
advice.c +5
-0+int error_ff_impossible (void ) +{ +error (_ ("Not possible to fast-forward, aborting." )); +return -1 ; +}Here's one, the idiom is just "return error", i.e it itself returns -1.
That would indeed be simpler; thanks for pointing that out.
Quoted 7 lines
FWIW I'd consider doing:
/* earlier, static scope */ static const char error_ff_impossible = N_("Not possible..."); /* later, function scope */ return error(error_ff_impossible);
Quoted 6 lines
Quoted 3 lines
It's a small difference, but for translators who use the jump-to-source while translating not having the indirection helps, and in this case it's just used 3 times...
Wouldn't jump-to-source take the user to the English text in
advice.ceither way? How does putting it in a static variable help?
Yes, sorry. I don't know what I was thinking there. What I said would only apply if _() was used inline, nevermind.
Quoted 12 lines
Quoted 11 lines
sequencer.c static int populate_opts_cb(const char *key, const char *value, void *data) · line 2772
Quoted 9 lines
[...]
if (parent && parse_commit(parent) < 0) /* TRANSLATORS: The first %s will be a "todo" command likesequencer.c +1
-1@@ -2764,7 +2769,7 @@ static int populate_opts_cb(const char *key, const char *value, void *data)else if (!strcmp (key,"options.record-origin" )) opts->record_origin =git_config_bool_or_int (key, value, &error_flag);else if (!strcmp (key,"options.allow-ff" )) - opts->allow_ff =git_config_bool_or_int (key, value, &error_flag); + opts->fast_forward =git_config_bool_or_int (key, value, &error_flag) ?FF_ALLOW :FF_NO ;Since we're on nits, we try to wrap at 80 characters.
Quoted 1 line
Thanks, I didn't know what the exact cutoff was.
It's not strictly adhered to, and depending on the code we'll have it be longer (sometimes much so) if it helps the general readability, e.g. long repetitive declarations or something. For this sort of thing it's generally preferred.
Quoted 18 lines · Junio C Hamano
Quoted 8 lines
Quoted 4 lines · Phillip Wood
Looking at origin/seen:builtin/pull.c we already check if we can fast-forward and unconditionally merge in that case irrespective of any '--rebase' option or pull.rebase config. It should be simple for pull to error out if '--ff-only' is given and we cannot fast-forward.
Quoted 8 lines
Excellent.
Even though teaching even more special case on the "git pull" side makes me feel somewhat dirty, but I think it would be a small price to pay, and the end result would save an useless fork whose sole purpose is to make the integration step after fetch fail when "pull" can easily tell, as you said, that it ought to fail, so overall it would probably be a net win.
Quoted 4 lines
Okay, so it sounds like I should just scrap this patch and try again, after "pull: cleanup autostash check" is in master, with a patch that only modifies
git pulland notgit rebase. (Unless someone more experienced wants to take over, which would be fine by me.)
I've just skimmed that whole part of the larger "what should we do" discussion here, and don't really have an opinion, but I see Phillip Wood replied to this downthread.
You can grab the branches Junio mentions in What's Cooking from
https://github.com/gitster/git.git, if you'd like to rebase on top of Felipe's (or from the ML).
And if you fetch from it with:
fetch = +refs/notes/amlog:refs/notes/amlog
And set:
[notes]
displayRef = refs/notes/amlog
You'll get mappings from the mails to the commits Junio applies.
(Note that they're not always 1=1 the same, even after ignoring Junio's Signed-off-by header, he'll sometimes fix them up as he queues them, might use a different base for "master" than you did etc.)
Hi Alex
Quoted 18 lines · Alex Henrie
Quoted 8 lines · Junio C Hamano
Quoted 4 lines · Phillip Wood
Looking at origin/seen:builtin/pull.c we already check if we can fast-forward and unconditionally merge in that case irrespective of any '--rebase' option or pull.rebase config. It should be simple for pull to error out if '--ff-only' is given and we cannot fast-forward.
Quoted 8 lines
Excellent.
Even though teaching even more special case on the "git pull" side makes me feel somewhat dirty, but I think it would be a small price to pay, and the end result would save an useless fork whose sole purpose is to make the integration step after fetch fail when "pull" can easily tell, as you said, that it ought to fail, so overall it would probably be a net win.
Quoted 4 lines
Okay, so it sounds like I should just scrap this patch and try again, after "pull: cleanup autostash check" is in master, with a patch that only modifies
git pulland notgit rebase. (Unless someone more experienced wants to take over, which would be fine by me.)
I don't think you need to wait, if necessary you could base your patches on top of that branch. Junio's latest what's cooking email said he was going to merge that branch into next so it is unlikely to change. In any case looking at the 'git diff origin/master origin/seen builtin/pull.c' I suspect the changes required won't conflict with that branch.
Quoted 2 lines
Thanks anyway to Phillip and Ævar: Your feedback will help me write better patches in the future.
You're welcome, I look forward to reading your future patches
Best wishes
Phillip
Quoted 2 lines
-Alex
Quoted 11 lines · Junio C Hamano
Quoted 4 lines · Phillip Wood
Looking at origin/seen:builtin/pull.c we already check if we can fast-forward and unconditionally merge in that case irrespective of any '--rebase' option or pull.rebase config. It should be simple for pull to error out if '--ff-only' is given and we cannot fast-forward.
Excellent.
Even though teaching even more special case on the "git pull" side makes me feel somewhat dirty,
It makes you feeld dirty for a reason.
Why don't you just actually try the proposal?
builtin/pull.c +3 -0
@@ -1052,6 +1052,9 @@ int cmd_pull(int argc, const char **argv, const char *prefix)show_advice_pull_non_ff (); } +if (!can_ff && (!opt_ff || !strcmp (opt_ff,"--ff-only" ))) +die ("unable to fast-forward" ); +if (opt_rebase) {int ret =0 ;int ran_ff =0 ;
Then:
./git pull . topic ./git pull --no-rebase . topic ./git pull --rebase . topic
From 1 to 10 how broken would you say that is?
-------------------t4013-diff-various.sh (Wstat: 256 Tests: 208 Failed: 91)
Failed tests: 1, 49-63, 67-69, 71-91, 101-116, 120-124
127-130, 138-141, 144-145, 147-150, 152-153
171-175, 189-193, 201-204 Non-zero exit status: 1t5521-pull-options.sh (Wstat: 256 Tests: 20 Failed: 2)
Failed tests: 12, 16
Non-zero exit status: 1t5524-pull-msg.sh (Wstat: 256 Tests: 3 Failed: 2)
Failed tests: 2-3
Non-zero exit status: 1t5520-pull.sh (Wstat: 256 Tests: 72 Failed: 39)
Failed tests: 16, 19, 23-24, 26-29, 33-41, 43-46, 48-53
55-57, 59-64, 69, 71-72
Non-zero exit status: 1t5533-push-cas.sh (Wstat: 256 Tests: 23 Failed: 2)
Failed tests: 21-22
Non-zero exit status: 1t5553-set-upstream.sh (Wstat: 256 Tests: 19 Failed: 6)
Failed tests: 11-14, 16-17
Non-zero exit status: 1t5604-clone-reference.sh (Wstat: 256 Tests: 33 Failed: 4)
Failed tests: 13-16
Non-zero exit status: 1t5572-pull-submodule.sh (Wstat: 256 Tests: 64 Failed: 3)
Failed tests: 62-64
Non-zero exit status: 1t6409-merge-subtree.sh (Wstat: 256 Tests: 12 Failed: 3)
Failed tests: 9, 11-12
Non-zero exit status: 1t6402-merge-rename.sh (Wstat: 256 Tests: 46 Failed: 8)
Failed tests: 2-8, 11
Non-zero exit status: 1t6417-merge-ours-theirs.sh (Wstat: 256 Tests: 7 Failed: 1)
Failed test: 6
Non-zero exit status: 1t7601-merge-pull-config.sh (Wstat: 256 Tests: 32 Failed: 3)
Failed tests: 11, 15-16
Non-zero exit status: 1t7603-merge-reduce-heads.sh (Wstat: 256 Tests: 13 Failed: 1)
Failed test: 3
Non-zero exit status: 1
Signature · 1 line
Felipe Contreras
Quoted 2 lines · Alex Henrie
I'm sending this patch as an RFC because I'm sure someone will find at least one thing that needs to be changed before it's committed.
FWIW that's true of most non-RFC patches :)
advice.c void list_config_advices(struct string_list *list, const char *prefix) · line 253
Quoted 5 lines
advice.c +5
-0+int error_ff_impossible (void ) +{ +error (_ ("Not possible to fast-forward, aborting." )); +return -1 ; +}
Here's one, the idiom is just "return error", i.e it itself returns -1.
FWIW I'd consider doing:
/* earlier, static scope */
static const char error_ff_impossible = N_("Not possible...");
/* later, function scope */
return error(error_ff_impossible);It's a small difference, but for translators who use the jump-to-source while translating not having the indirection helps, and in this case it's just used 3 times...
sequencer.c static int populate_opts_cb(const char *key, const char *value, void *data) · line 2772
Quoted 9 lines
[...]
sequencer.c +1
-1if (parent &&parse_commit (parent) <0 )/* TRANSLATORS: The first %s will be a "todo" command like @@ -2764,7 +2769,7 @@ static int populate_opts_cb(const char *key, const char *value, void *data)else if (!strcmp (key,"options.record-origin" )) opts->record_origin =git_config_bool_or_int (key, value, &error_flag);else if (!strcmp (key,"options.allow-ff" )) - opts->allow_ff =git_config_bool_or_int (key, value, &error_flag); + opts->fast_forward =git_config_bool_or_int (key, value, &error_flag) ?FF_ALLOW :FF_NO ;
Since we're on nits, we try to wrap at 80 characters.
t/t3420-rebase-autostash.sh test_expect_success "rebase: fast-forward rebase" ' · line 253
Quoted 5 lines
t/t3420-rebase-autostash.sh +5
-0+test_expect_success "rebase: impossible fast-forward rebase" ' + test_config rebase.autostash true && + git reset --hard && + echo dirty >>file1 && + (git rebase --ff-only unrelated-onto-branch || true) &&
Never "||" git commands, better as test_might_fail. We don't want to hide segfaults.
I saw Phillip Wood had some comments on the rest, I didn't test this, just skimmed it, but generally LGTM from a glance, not getting down to the nuts of more deeply inspecting the logic.
Quoted 4 lines · Alex Henrie
The warning about pulling without specifying how to reconcile divergent branches says that after setting pull.rebase to true, --ff-only can still be passed on the command line to require a fast-forward. Make that actually work.
I don't see any value in doing git rebase --ff-only. What is the difference with git merge --ff-only?
Presumably this isn't meant to to be called directly by the user, but only by git pull, so it's trying to address my comment [1]:
Quoted 2 lines
You can also pass --rebase, --no-rebase, or --ff-only on the command line to override the configured default per invocation.
Can I?
git -c pull.rebase=true pull --ff-only
--ff-only doesn't seem to be overriding the configuration.
Passing --ff-only to git rebase doesn't solve the problem I was pointing out, only half of it.
Sure, now this works:
git -c pull.rebase=true pull --ff-only
But --ff-only is not really overriding anything, now you are passing the problem along.
Consider it the other way around:
git -c pull.ff=only pull --rebase
Is --rebase overriding anything?
No, now all these three fail:
git -c pull.ff=only pull git -c pull.ff=only pull --rebase git -c pull.ff=only pull --merge
This is making the situation even worse.
Junio already made the same mistake [2], and I already pointed out why that doesn't work [3].
This is what we want:
1. git pull # fail by default unless it's a fast-forward
2. git pull --merge # force a merge (unless it's a fast-forward)
3. git pull --rebase # force a rebase (unless it's a fast-forward)
If you make git rebase honor --ff-only, and you make --ff-only the default, then git pull --rebase will *always* fail (unless it's a fast-forward).
We want this:
git -c pull.ff=only pull --rebase
To *ignore* pull.ff=only, not honor it.
I already explored all the options, which is why I maintain that the only reasonable option is an orthogonal configuration:
pull.mode=fast-forward
Cheers.
[1] https://lore.kernel.org/git/[email protected]/
[2] https://lore.kernel.org/git/[email protected]/
[3] https://lore.kernel.org/git/CAMP44s08mEyYqbjOeTeS46CngrbQMqP2=cMr1dtRLLk_BLAq3w@mail.gmail.com/
Signature · 1 line
Felipe Contreras