Skip to content

Commit f8094a2

Browse files
committed
pull: make code more similar to the shell script again
When converting the pull command to a builtin, the require_clean_work_tree() function was renamed and the pull-specific parts hard-coded. This makes it impossible to reuse the code, so let's modify the code to make it more similar to the original shell script again. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
1 parent 4f92497 commit f8094a2

1 file changed

Lines changed: 18 additions & 10 deletions

File tree

builtin/pull.c

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -345,31 +345,38 @@ static int has_uncommitted_changes()
345345
* If the work tree has unstaged or uncommitted changes, dies with the
346346
* appropriate message.
347347
*/
348-
static void die_on_unclean_work_tree()
348+
static int require_clean_work_tree(const char *action, const char *hint,
349+
int gently)
349350
{
350351
struct lock_file *lock_file = xcalloc(1, sizeof(*lock_file));
351-
int do_die = 0;
352+
int err = 0;
352353

353354
hold_locked_index(lock_file, 0);
354355
refresh_cache(REFRESH_QUIET);
355356
update_index_if_able(&the_index, lock_file);
356357
rollback_lock_file(lock_file);
357358

358359
if (has_unstaged_changes()) {
359-
error(_("Cannot pull with rebase: You have unstaged changes."));
360-
do_die = 1;
360+
error(_("Cannot %s: You have unstaged changes."), action);
361+
err = 1;
361362
}
362363

363364
if (has_uncommitted_changes()) {
364-
if (do_die)
365+
if (err)
365366
error(_("Additionally, your index contains uncommitted changes."));
366367
else
367-
error(_("Cannot pull with rebase: Your index contains uncommitted changes."));
368-
do_die = 1;
368+
error(_("Cannot %s: Your index contains uncommitted changes."), action);
369+
err = 1;
369370
}
370371

371-
if (do_die)
372-
exit(1);
372+
if (err) {
373+
if (hint)
374+
error("%s", hint);
375+
if (!gently)
376+
exit(err);
377+
}
378+
379+
return err;
373380
}
374381

375382
/**
@@ -842,7 +849,8 @@ int cmd_pull(int argc, const char **argv, const char *prefix)
842849

843850
git_config_get_bool("rebase.autostash", &autostash);
844851
if (!autostash)
845-
die_on_unclean_work_tree();
852+
require_clean_work_tree("pull with rebase",
853+
"Please commit or stash them.", 0);
846854

847855
if (get_rebase_fork_point(rebase_fork_point, repo, *refspecs))
848856
hashclr(rebase_fork_point);

0 commit comments

Comments
 (0)