aboutsummaryrefslogtreecommitdiff
path: root/builtin
diff options
context:
space:
mode:
authorJohannes Schindelin <johannes.schindelin@gmx.de>2016-10-07 18:08:34 +0200
committerJunio C Hamano <gitster@pobox.com>2016-10-07 09:29:31 -0700
commitea63b393ec76484690733d6f589c9e67fedbaa78 (patch)
tree7b6c869d072dca69598d0190c5de8be8db3e43c8 /builtin
parent338bc8d81897d19f4795114e4e6a59d6ca44d1db (diff)
downloadgit-ea63b393ec76484690733d6f589c9e67fedbaa78.tar.gz
git-ea63b393ec76484690733d6f589c9e67fedbaa78.tar.xz
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>
Diffstat (limited to 'builtin')
-rw-r--r--builtin/pull.c30
1 files changed, 20 insertions, 10 deletions
diff --git a/builtin/pull.c b/builtin/pull.c
index d4bd6350f..58fc176db 100644
--- a/builtin/pull.c
+++ b/builtin/pull.c
@@ -365,10 +365,11 @@ static int has_uncommitted_changes(void)
* If the work tree has unstaged or uncommitted changes, dies with the
* appropriate message.
*/
-static void die_on_unclean_work_tree(void)
+static int require_clean_work_tree(const char *action, const char *hint,
+ int gently)
{
struct lock_file *lock_file = xcalloc(1, sizeof(*lock_file));
- int do_die = 0;
+ int err = 0;
hold_locked_index(lock_file, 0);
refresh_cache(REFRESH_QUIET);
@@ -376,20 +377,28 @@ static void die_on_unclean_work_tree(void)
rollback_lock_file(lock_file);
if (has_unstaged_changes()) {
- error(_("Cannot pull with rebase: You have unstaged changes."));
- do_die = 1;
+ /* TRANSLATORS: the action is e.g. "pull with rebase" */
+ error(_("Cannot %s: You have unstaged changes."), _(action));
+ err = 1;
}
if (has_uncommitted_changes()) {
- if (do_die)
+ if (err)
error(_("Additionally, your index contains uncommitted changes."));
else
- error(_("Cannot pull with rebase: Your index contains uncommitted changes."));
- do_die = 1;
+ error(_("Cannot %s: Your index contains uncommitted changes."),
+ _(action));
+ err = 1;
}
- if (do_die)
- exit(1);
+ if (err) {
+ if (hint)
+ error("%s", hint);
+ if (!gently)
+ exit(128);
+ }
+
+ return err;
}
/**
@@ -875,7 +884,8 @@ int cmd_pull(int argc, const char **argv, const char *prefix)
die(_("Updating an unborn branch with changes added to the index."));
if (!autostash)
- die_on_unclean_work_tree();
+ require_clean_work_tree(N_("pull with rebase"),
+ _("please commit or stash them."), 0);
if (get_rebase_fork_point(rebase_fork_point, repo, *refspecs))
hashclr(rebase_fork_point);