Skip to content

Commit 4f92497

Browse files
committed
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>
1 parent dc84ad2 commit 4f92497

1 file changed

Lines changed: 8 additions & 8 deletions

File tree

builtin/pull.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -308,12 +308,12 @@ static enum rebase_type config_get_rebase(void)
308308
/**
309309
* Returns 1 if there are unstaged changes, 0 otherwise.
310310
*/
311-
static int has_unstaged_changes(const char *prefix)
311+
static int has_unstaged_changes()
312312
{
313313
struct rev_info rev_info;
314314
int result;
315315

316-
init_revisions(&rev_info, prefix);
316+
init_revisions(&rev_info, NULL);
317317
DIFF_OPT_SET(&rev_info.diffopt, IGNORE_SUBMODULES);
318318
DIFF_OPT_SET(&rev_info.diffopt, QUICK);
319319
diff_setup_done(&rev_info.diffopt);
@@ -324,15 +324,15 @@ static int has_unstaged_changes(const char *prefix)
324324
/**
325325
* Returns 1 if there are uncommitted changes, 0 otherwise.
326326
*/
327-
static int has_uncommitted_changes(const char *prefix)
327+
static int has_uncommitted_changes()
328328
{
329329
struct rev_info rev_info;
330330
int result;
331331

332332
if (is_cache_unborn())
333333
return 0;
334334

335-
init_revisions(&rev_info, prefix);
335+
init_revisions(&rev_info, NULL);
336336
DIFF_OPT_SET(&rev_info.diffopt, IGNORE_SUBMODULES);
337337
DIFF_OPT_SET(&rev_info.diffopt, QUICK);
338338
add_head_to_pending(&rev_info);
@@ -345,7 +345,7 @@ static int has_uncommitted_changes(const char *prefix)
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(const char *prefix)
348+
static void die_on_unclean_work_tree()
349349
{
350350
struct lock_file *lock_file = xcalloc(1, sizeof(*lock_file));
351351
int do_die = 0;
@@ -355,12 +355,12 @@ static void die_on_unclean_work_tree(const char *prefix)
355355
update_index_if_able(&the_index, lock_file);
356356
rollback_lock_file(lock_file);
357357

358-
if (has_unstaged_changes(prefix)) {
358+
if (has_unstaged_changes()) {
359359
error(_("Cannot pull with rebase: You have unstaged changes."));
360360
do_die = 1;
361361
}
362362

363-
if (has_uncommitted_changes(prefix)) {
363+
if (has_uncommitted_changes()) {
364364
if (do_die)
365365
error(_("Additionally, your index contains uncommitted changes."));
366366
else
@@ -842,7 +842,7 @@ int cmd_pull(int argc, const char **argv, const char *prefix)
842842

843843
git_config_get_bool("rebase.autostash", &autostash);
844844
if (!autostash)
845-
die_on_unclean_work_tree(prefix);
845+
die_on_unclean_work_tree();
846846

847847
if (get_rebase_fork_point(rebase_fork_point, repo, *refspecs))
848848
hashclr(rebase_fork_point);

0 commit comments

Comments
 (0)