Skip to content

Commit ea63b39

Browse files
dschogitster
authored andcommitted
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. Note: when the hint "Please commit or stash them" was introduced first, Git did not have the convention of continuing error messages in lower case, but now we do have that convention, therefore we reintroduce this hint down-cased, obeying said convention. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent 338bc8d commit ea63b39

File tree

1 file changed

+20
-10
lines changed

1 file changed

+20
-10
lines changed

builtin/pull.c

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -365,31 +365,40 @@ static int has_uncommitted_changes(void)
365365
* If the work tree has unstaged or uncommitted changes, dies with the
366366
* appropriate message.
367367
*/
368-
static void die_on_unclean_work_tree(void)
368+
static int require_clean_work_tree(const char *action, const char *hint,
369+
int gently)
369370
{
370371
struct lock_file *lock_file = xcalloc(1, sizeof(*lock_file));
371-
int do_die = 0;
372+
int err = 0;
372373

373374
hold_locked_index(lock_file, 0);
374375
refresh_cache(REFRESH_QUIET);
375376
update_index_if_able(&the_index, lock_file);
376377
rollback_lock_file(lock_file);
377378

378379
if (has_unstaged_changes()) {
379-
error(_("Cannot pull with rebase: You have unstaged changes."));
380-
do_die = 1;
380+
/* TRANSLATORS: the action is e.g. "pull with rebase" */
381+
error(_("Cannot %s: You have unstaged changes."), _(action));
382+
err = 1;
381383
}
382384

383385
if (has_uncommitted_changes()) {
384-
if (do_die)
386+
if (err)
385387
error(_("Additionally, your index contains uncommitted changes."));
386388
else
387-
error(_("Cannot pull with rebase: Your index contains uncommitted changes."));
388-
do_die = 1;
389+
error(_("Cannot %s: Your index contains uncommitted changes."),
390+
_(action));
391+
err = 1;
389392
}
390393

391-
if (do_die)
392-
exit(1);
394+
if (err) {
395+
if (hint)
396+
error("%s", hint);
397+
if (!gently)
398+
exit(128);
399+
}
400+
401+
return err;
393402
}
394403

395404
/**
@@ -875,7 +884,8 @@ int cmd_pull(int argc, const char **argv, const char *prefix)
875884
die(_("Updating an unborn branch with changes added to the index."));
876885

877886
if (!autostash)
878-
die_on_unclean_work_tree();
887+
require_clean_work_tree(N_("pull with rebase"),
888+
_("please commit or stash them."), 0);
879889

880890
if (get_rebase_fork_point(rebase_fork_point, repo, *refspecs))
881891
hashclr(rebase_fork_point);

0 commit comments

Comments
 (0)