Skip to content

Commit 051910a

Browse files
prertikgitster
authored andcommitted
builtin rebase: support --autosquash
This commit adds support for the `--autosquash` option which is used to automatically squash the commits marked as `squash` or `fixup` in their messages. This is converted following `git-legacy-rebase.sh` closely. This option can also be configured via the Git config setting rebase.autosquash. To support this, we also add a custom rebase_config() function in this commit that will be used instead (and falls back to) git_default_config(). Signed-off-by: Pratik Karki <[email protected]> Signed-off-by: Johannes Schindelin <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 002ee2f commit 051910a

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

builtin/rebase.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ struct rebase_options {
9696
int signoff;
9797
int allow_rerere_autoupdate;
9898
int keep_empty;
99+
int autosquash;
99100
};
100101

101102
static int is_interactive(struct rebase_options *opts)
@@ -295,6 +296,7 @@ static int run_specific_rebase(struct rebase_options *opts)
295296
opts->allow_rerere_autoupdate ?
296297
"--rerere-autoupdate" : "--no-rerere-autoupdate");
297298
add_var(&script_snippet, "keep_empty", opts->keep_empty ? "yes" : "");
299+
add_var(&script_snippet, "autosquash", opts->autosquash ? "t" : "");
298300

299301
switch (opts->type) {
300302
case REBASE_AM:
@@ -455,6 +457,11 @@ static int rebase_config(const char *var, const char *value, void *data)
455457
return 0;
456458
}
457459

460+
if (!strcmp(var, "rebase.autosquash")) {
461+
opts->autosquash = git_config_bool(var, value);
462+
return 0;
463+
}
464+
458465
return git_default_config(var, value, data);
459466
}
460467

@@ -609,6 +616,9 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
609616
"conflict")),
610617
OPT_BOOL('k', "keep-empty", &options.keep_empty,
611618
N_("preserve empty commits during rebase")),
619+
OPT_BOOL(0, "autosquash", &options.autosquash,
620+
N_("move commits that begin with "
621+
"squash!/fixup! under -i")),
612622
OPT_END(),
613623
};
614624

0 commit comments

Comments
 (0)