Skip to content

Commit aa3dfaa

Browse files
committed
Merge 'rebase--helper' into HEAD
2 parents d5cb9cb + e1795cf commit aa3dfaa

17 files changed

+1631
-367
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@
114114
/git-read-tree
115115
/git-rebase
116116
/git-rebase--am
117+
/git-rebase--helper
117118
/git-rebase--interactive
118119
/git-rebase--merge
119120
/git-receive-pack

Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -919,6 +919,7 @@ BUILTIN_OBJS += builtin/prune.o
919919
BUILTIN_OBJS += builtin/pull.o
920920
BUILTIN_OBJS += builtin/push.o
921921
BUILTIN_OBJS += builtin/read-tree.o
922+
BUILTIN_OBJS += builtin/rebase--helper.o
922923
BUILTIN_OBJS += builtin/receive-pack.o
923924
BUILTIN_OBJS += builtin/reflog.o
924925
BUILTIN_OBJS += builtin/remote.o

builtin.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ extern int cmd_prune_packed(int argc, const char **argv, const char *prefix);
102102
extern int cmd_pull(int argc, const char **argv, const char *prefix);
103103
extern int cmd_push(int argc, const char **argv, const char *prefix);
104104
extern int cmd_read_tree(int argc, const char **argv, const char *prefix);
105+
extern int cmd_rebase__helper(int argc, const char **argv, const char *prefix);
105106
extern int cmd_receive_pack(int argc, const char **argv, const char *prefix);
106107
extern int cmd_reflog(int argc, const char **argv, const char *prefix);
107108
extern int cmd_remote(int argc, const char **argv, const char *prefix);

builtin/commit.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ static void determine_whence(struct wt_status *s)
173173
whence = FROM_MERGE;
174174
else if (file_exists(git_path_cherry_pick_head())) {
175175
whence = FROM_CHERRY_PICK;
176-
if (file_exists(git_path(SEQ_DIR)))
176+
if (file_exists(git_path_seq_dir()))
177177
sequencer_in_use = 1;
178178
}
179179
else

builtin/pull.c

Lines changed: 3 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include "revision.h"
1818
#include "tempfile.h"
1919
#include "lockfile.h"
20+
#include "wt-status.h"
2021

2122
enum rebase_type {
2223
REBASE_INVALID = -1,
@@ -325,73 +326,6 @@ static int git_pull_config(const char *var, const char *value, void *cb)
325326
return git_default_config(var, value, cb);
326327
}
327328

328-
/**
329-
* Returns 1 if there are unstaged changes, 0 otherwise.
330-
*/
331-
static int has_unstaged_changes(const char *prefix)
332-
{
333-
struct rev_info rev_info;
334-
int result;
335-
336-
init_revisions(&rev_info, prefix);
337-
DIFF_OPT_SET(&rev_info.diffopt, IGNORE_SUBMODULES);
338-
DIFF_OPT_SET(&rev_info.diffopt, QUICK);
339-
diff_setup_done(&rev_info.diffopt);
340-
result = run_diff_files(&rev_info, 0);
341-
return diff_result_code(&rev_info.diffopt, result);
342-
}
343-
344-
/**
345-
* Returns 1 if there are uncommitted changes, 0 otherwise.
346-
*/
347-
static int has_uncommitted_changes(const char *prefix)
348-
{
349-
struct rev_info rev_info;
350-
int result;
351-
352-
if (is_cache_unborn())
353-
return 0;
354-
355-
init_revisions(&rev_info, prefix);
356-
DIFF_OPT_SET(&rev_info.diffopt, IGNORE_SUBMODULES);
357-
DIFF_OPT_SET(&rev_info.diffopt, QUICK);
358-
add_head_to_pending(&rev_info);
359-
diff_setup_done(&rev_info.diffopt);
360-
result = run_diff_index(&rev_info, 1);
361-
return diff_result_code(&rev_info.diffopt, result);
362-
}
363-
364-
/**
365-
* If the work tree has unstaged or uncommitted changes, dies with the
366-
* appropriate message.
367-
*/
368-
static void die_on_unclean_work_tree(const char *prefix)
369-
{
370-
struct lock_file *lock_file = xcalloc(1, sizeof(*lock_file));
371-
int do_die = 0;
372-
373-
hold_locked_index(lock_file, 0);
374-
refresh_cache(REFRESH_QUIET);
375-
update_index_if_able(&the_index, lock_file);
376-
rollback_lock_file(lock_file);
377-
378-
if (has_unstaged_changes(prefix)) {
379-
error(_("Cannot pull with rebase: You have unstaged changes."));
380-
do_die = 1;
381-
}
382-
383-
if (has_uncommitted_changes(prefix)) {
384-
if (do_die)
385-
error(_("Additionally, your index contains uncommitted changes."));
386-
else
387-
error(_("Cannot pull with rebase: Your index contains uncommitted changes."));
388-
do_die = 1;
389-
}
390-
391-
if (do_die)
392-
exit(1);
393-
}
394-
395329
/**
396330
* Appends merge candidates from FETCH_HEAD that are not marked not-for-merge
397331
* into merge_heads.
@@ -875,7 +809,8 @@ int cmd_pull(int argc, const char **argv, const char *prefix)
875809
die(_("Updating an unborn branch with changes added to the index."));
876810

877811
if (!autostash)
878-
die_on_unclean_work_tree(prefix);
812+
require_clean_work_tree("pull with rebase",
813+
"Please commit or stash them.", 1, 0);
879814

880815
if (get_rebase_fork_point(rebase_fork_point, repo, *refspecs))
881816
hashclr(rebase_fork_point);

builtin/rebase--helper.c

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#include "builtin.h"
2+
#include "cache.h"
3+
#include "parse-options.h"
4+
#include "sequencer.h"
5+
6+
static const char * const builtin_rebase_helper_usage[] = {
7+
N_("git rebase--helper [<options>]"),
8+
NULL
9+
};
10+
11+
int cmd_rebase__helper(int argc, const char **argv, const char *prefix)
12+
{
13+
struct replay_opts opts = REPLAY_OPTS_INIT;
14+
enum {
15+
CONTINUE = 1, ABORT
16+
} command = 0;
17+
struct option options[] = {
18+
OPT_BOOL(0, "ff", &opts.allow_ff, N_("allow fast-forward")),
19+
OPT_CMDMODE(0, "continue", &command, N_("continue rebase"),
20+
CONTINUE),
21+
OPT_CMDMODE(0, "abort", &command, N_("abort rebase"),
22+
ABORT),
23+
OPT_END()
24+
};
25+
26+
git_config(git_default_config, NULL);
27+
28+
opts.action = REPLAY_INTERACTIVE_REBASE;
29+
opts.allow_ff = 1;
30+
opts.allow_empty = 1;
31+
32+
argc = parse_options(argc, argv, NULL, options,
33+
builtin_rebase_helper_usage, PARSE_OPT_KEEP_ARGV0);
34+
35+
if (command == CONTINUE && argc == 1)
36+
return !!sequencer_continue(&opts);
37+
if (command == ABORT && argc == 1)
38+
return !!sequencer_remove_state(&opts);
39+
usage_with_options(builtin_rebase_helper_usage, options);
40+
}

builtin/revert.c

Lines changed: 18 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ static void verify_opt_compatible(const char *me, const char *base_opt, ...)
7171
die(_("%s: %s cannot be used with %s"), me, this_opt, base_opt);
7272
}
7373

74-
static void parse_args(int argc, const char **argv, struct replay_opts *opts)
74+
static int run_sequencer(int argc, const char **argv, struct replay_opts *opts)
7575
{
7676
const char * const * usage_str = revert_or_cherry_pick_usage(opts);
7777
const char *me = action_name(opts);
@@ -115,25 +115,15 @@ static void parse_args(int argc, const char **argv, struct replay_opts *opts)
115115
if (opts->keep_redundant_commits)
116116
opts->allow_empty = 1;
117117

118-
/* Set the subcommand */
119-
if (cmd == 'q')
120-
opts->subcommand = REPLAY_REMOVE_STATE;
121-
else if (cmd == 'c')
122-
opts->subcommand = REPLAY_CONTINUE;
123-
else if (cmd == 'a')
124-
opts->subcommand = REPLAY_ROLLBACK;
125-
else
126-
opts->subcommand = REPLAY_NONE;
127-
128118
/* Check for incompatible command line arguments */
129-
if (opts->subcommand != REPLAY_NONE) {
119+
if (cmd) {
130120
char *this_operation;
131-
if (opts->subcommand == REPLAY_REMOVE_STATE)
121+
if (cmd == 'q')
132122
this_operation = "--quit";
133-
else if (opts->subcommand == REPLAY_CONTINUE)
123+
else if (cmd == 'c')
134124
this_operation = "--continue";
135125
else {
136-
assert(opts->subcommand == REPLAY_ROLLBACK);
126+
assert(cmd == 'a');
137127
this_operation = "--abort";
138128
}
139129

@@ -156,7 +146,7 @@ static void parse_args(int argc, const char **argv, struct replay_opts *opts)
156146
"--edit", opts->edit,
157147
NULL);
158148

159-
if (opts->subcommand != REPLAY_NONE) {
149+
if (cmd) {
160150
opts->revs = NULL;
161151
} else {
162152
struct setup_revision_opt s_r_opt;
@@ -174,35 +164,39 @@ static void parse_args(int argc, const char **argv, struct replay_opts *opts)
174164

175165
if (argc > 1)
176166
usage_with_options(usage_str, options);
167+
168+
if (cmd == 'q')
169+
return sequencer_remove_state(opts);
170+
if (cmd == 'c')
171+
return sequencer_continue(opts);
172+
if (cmd == 'a')
173+
return sequencer_rollback(opts);
174+
return sequencer_pick_revisions(opts);
177175
}
178176

179177
int cmd_revert(int argc, const char **argv, const char *prefix)
180178
{
181-
struct replay_opts opts;
179+
struct replay_opts opts = REPLAY_OPTS_INIT;
182180
int res;
183181

184-
memset(&opts, 0, sizeof(opts));
185182
if (isatty(0))
186183
opts.edit = 1;
187184
opts.action = REPLAY_REVERT;
188185
git_config(git_default_config, NULL);
189-
parse_args(argc, argv, &opts);
190-
res = sequencer_pick_revisions(&opts);
186+
res = run_sequencer(argc, argv, &opts);
191187
if (res < 0)
192188
die(_("revert failed"));
193189
return res;
194190
}
195191

196192
int cmd_cherry_pick(int argc, const char **argv, const char *prefix)
197193
{
198-
struct replay_opts opts;
194+
struct replay_opts opts = REPLAY_OPTS_INIT;
199195
int res;
200196

201-
memset(&opts, 0, sizeof(opts));
202197
opts.action = REPLAY_PICK;
203198
git_config(git_default_config, NULL);
204-
parse_args(argc, argv, &opts);
205-
res = sequencer_pick_revisions(&opts);
199+
res = run_sequencer(argc, argv, &opts);
206200
if (res < 0)
207201
die(_("cherry-pick failed"));
208202
return res;

git-rebase--interactive.sh

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1059,6 +1059,10 @@ git_rebase__interactive () {
10591059

10601060
case "$action" in
10611061
continue)
1062+
if test ! -d "$rewritten"
1063+
then
1064+
exec git rebase--helper ${force_rebase:+--no-ff} --continue
1065+
fi
10621066
# do we have anything to commit?
10631067
if git diff-index --cached --quiet HEAD --
10641068
then
@@ -1118,6 +1122,10 @@ first and then run 'git rebase --continue' again.")"
11181122
skip)
11191123
git rerere clear
11201124

1125+
if test ! -d "$rewritten"
1126+
then
1127+
exec git rebase--helper ${force_rebase:+--no-ff} --continue
1128+
fi
11211129
do_rest
11221130
return 0
11231131
;;
@@ -1307,6 +1315,11 @@ expand_todo_ids
13071315
test -d "$rewritten" || test -n "$force_rebase" || skip_unnecessary_picks
13081316

13091317
checkout_onto
1318+
if test -z "$rebase_root" && test ! -d "$rewritten"
1319+
then
1320+
require_clean_work_tree "rebase"
1321+
exec git rebase--helper ${force_rebase:+--no-ff} --continue
1322+
fi
13101323
do_rest
13111324

13121325
}

git.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -451,6 +451,7 @@ static struct cmd_struct commands[] = {
451451
{ "pull", cmd_pull, RUN_SETUP | NEED_WORK_TREE },
452452
{ "push", cmd_push, RUN_SETUP },
453453
{ "read-tree", cmd_read_tree, RUN_SETUP },
454+
{ "rebase--helper", cmd_rebase__helper, RUN_SETUP | NEED_WORK_TREE },
454455
{ "receive-pack", cmd_receive_pack },
455456
{ "reflog", cmd_reflog, RUN_SETUP },
456457
{ "remote", cmd_remote, RUN_SETUP },

merge.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,8 @@ int checkout_fast_forward(const unsigned char *head,
5757

5858
refresh_cache(REFRESH_QUIET);
5959

60-
hold_locked_index(lock_file, 1);
60+
if (hold_locked_index(lock_file, 0) < 0)
61+
return -1;
6162

6263
memset(&trees, 0, sizeof(trees));
6364
memset(&opts, 0, sizeof(opts));
@@ -90,7 +91,9 @@ int checkout_fast_forward(const unsigned char *head,
9091
}
9192
if (unpack_trees(nr_trees, t, &opts))
9293
return -1;
93-
if (write_locked_index(&the_index, lock_file, COMMIT_LOCK))
94-
die(_("unable to write new index file"));
94+
if (write_locked_index(&the_index, lock_file, COMMIT_LOCK)) {
95+
rollback_lock_file(lock_file);
96+
return error(_("unable to write new index file"));
97+
}
9598
return 0;
9699
}

0 commit comments

Comments
 (0)