pull: drop confusing prefix parameter of die_on_unclean_work_tree()

In cmd_pull(), when verifying that there are no changes preventing a rebasing pull, we diligently pass the prefix parameter to the die_on_unclean_work_tree() function which in turn diligently passes it to the has_unstaged_changes() and has_uncommitted_changes() functions. The casual reader might now be curious (as this developer was) whether that means that calling `git pull --rebase` in a subdirectory will ignore unstaged changes in other parts of the working directory. And be puzzled that `git pull --rebase` (correctly) complains about those changes outside of the current directory. The puzzle is easily resolved: while we take pains to pass around the prefix and even pass it to init_revisions(), the fact that no paths are passed to init_revisions() ensures that the prefix is simply ignored. That, combined with the fact that we will *always* want a *full* working directory check before running a rebasing pull, is reason enough to simply do away with the actual prefix parameter and to pass NULL instead, as if we were running this from the top-level working directory anyway. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Johannes Schindelin committed Oct 7, 2016 at 18:08 UTC 338bc8d81897d19f4795114e4e6a59d6ca44d1db
1 file changed +8 -8
builtin/pull.c
+8 -8
@@ -328,12 +328,12 @@ static int git_pull_config(const char *var, const char *value, void *cb)
328 /**
329 * Returns 1 if there are unstaged changes, 0 otherwise.
330 */
331 -static int has_unstaged_changes(const char *prefix)
331 +static int has_unstaged_changes(void)
332 {
333 struct rev_info rev_info;
334 int result;
335
336 - init_revisions(&rev_info, prefix);
336 + init_revisions(&rev_info, NULL);
337 DIFF_OPT_SET(&rev_info.diffopt, IGNORE_SUBMODULES);
338 DIFF_OPT_SET(&rev_info.diffopt, QUICK);
339 diff_setup_done(&rev_info.diffopt);
@@ -344,7 +344,7 @@ static int has_unstaged_changes(const char *prefix)
344 /**
345 * Returns 1 if there are uncommitted changes, 0 otherwise.
346 */
347 -static int has_uncommitted_changes(const char *prefix)
347 +static int has_uncommitted_changes(void)
348 {
349 struct rev_info rev_info;
350 int result;
@@ -352,7 +352,7 @@ static int has_uncommitted_changes(const char *prefix)
352 if (is_cache_unborn())
353 return 0;
354
355 - init_revisions(&rev_info, prefix);
355 + init_revisions(&rev_info, NULL);
356 DIFF_OPT_SET(&rev_info.diffopt, IGNORE_SUBMODULES);
357 DIFF_OPT_SET(&rev_info.diffopt, QUICK);
358 add_head_to_pending(&rev_info);
@@ -365,7 +365,7 @@ static int has_uncommitted_changes(const char *prefix)
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)
368 +static void die_on_unclean_work_tree(void)
369 {
370 struct lock_file *lock_file = xcalloc(1, sizeof(*lock_file));
371 int do_die = 0;
@@ -375,12 +375,12 @@ static void die_on_unclean_work_tree(const char *prefix)
375 update_index_if_able(&the_index, lock_file);
376 rollback_lock_file(lock_file);
377
378 - if (has_unstaged_changes(prefix)) {
378 + if (has_unstaged_changes()) {
379 error(_("Cannot pull with rebase: You have unstaged changes."));
380 do_die = 1;
381 }
382
383 - if (has_uncommitted_changes(prefix)) {
383 + if (has_uncommitted_changes()) {
384 if (do_die)
385 error(_("Additionally, your index contains uncommitted changes."));
386 else
@@ -875,7 +875,7 @@ int cmd_pull(int argc, const char **argv, const char *prefix)
875 die(_("Updating an unborn branch with changes added to the index."));
876
877 if (!autostash)
878 - die_on_unclean_work_tree(prefix);
878 + die_on_unclean_work_tree();
879
880 if (get_rebase_fork_point(rebase_fork_point, repo, *refspecs))
881 hashclr(rebase_fork_point);