@@ -33,6 +33,10 @@ OPTIONS
--merge::
Forces a merge.
+-r::
+--rebase::
+ Forces a rebase.
+
SEE ALSO
--------
linkgit:git-fetch[1], linkgit:git-fast-forward[1],
@@ -9,7 +9,8 @@
enum update_mode_type {
UPDATE_MODE_FAST_FORWARD = 0,
- UPDATE_MODE_MERGE
+ UPDATE_MODE_MERGE,
+ UPDATE_MODE_REBASE
};
static enum update_mode_type mode = UPDATE_MODE_FAST_FORWARD;
@@ -26,6 +27,9 @@ static struct option update_options[] = {
OPT_SET_INT_F('m', "merge", &mode,
N_("incorporate changes by merging"),
UPDATE_MODE_MERGE, PARSE_OPT_NONEG),
+ OPT_SET_INT_F('r', "rebase", &mode,
+ N_("incorporate changes by rebasing"),
+ UPDATE_MODE_REBASE, PARSE_OPT_NONEG),
OPT_END()
};
@@ -66,6 +70,18 @@ static int run_merge(void)
return ret;
}
+static int run_rebase(void)
+{
+ int ret;
+ struct strvec args = STRVEC_INIT;
+
+ strvec_pushl(&args, "rebase", "FETCH_HEAD", NULL);
+
+ ret = run_command_v_opt(args.v, RUN_GIT_CMD);
+ strvec_clear(&args);
+ return ret;
+}
+
int cmd_update(int argc, const char **argv, const char *prefix)
{
if (!getenv("GIT_REFLOG_ACTION"))
@@ -86,6 +102,8 @@ int cmd_update(int argc, const char **argv, const char *prefix)
return run_fast_forward();
if (mode == UPDATE_MODE_MERGE)
return run_merge();
+ if (mode == UPDATE_MODE_REBASE)
+ return run_rebase();
return 1;
}
@@ -67,4 +67,21 @@ test_expect_success 'git update non-fast-forward with merge' '
)
'
+test_expect_success 'git update non-fast-forward with rebase' '
+ test_when_finished "rm -rf test" &&
+ (
+ git clone . test &&
+ cd test &&
+ git checkout -b other master^ &&
+ >new &&
+ git add new &&
+ git commit -m new &&
+ git checkout -b test -t other &&
+ git reset --hard master &&
+ git update --rebase &&
+ test_cmp_rev @^ other &&
+ test_must_fail git rev-parse --verify -q @^2
+ )
+'
+
test_done
Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com> --- Documentation/git-update.txt | 4 ++++ builtin/update.c | 20 +++++++++++++++++++- t/t5563-update.sh | 17 +++++++++++++++++ 3 files changed, 40 insertions(+), 1 deletion(-)