Skip to content

Commit 338bc8d

Browse files
dschogitster
authored andcommitted
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>
1 parent cda1bbd commit 338bc8d

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

builtin/pull.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -328,12 +328,12 @@ static int git_pull_config(const char *var, const char *value, void *cb)
328328
/**
329329
* Returns 1 if there are unstaged changes, 0 otherwise.
330330
*/
331-
static int has_unstaged_changes(const char *prefix)
331+
static int has_unstaged_changes(void)
332332
{
333333
struct rev_info rev_info;
334334
int result;
335335

336-
init_revisions(&rev_info, prefix);
336+
init_revisions(&rev_info, NULL);
337337
DIFF_OPT_SET(&rev_info.diffopt, IGNORE_SUBMODULES);
338338
DIFF_OPT_SET(&rev_info.diffopt, QUICK);
339339
diff_setup_done(&rev_info.diffopt);
@@ -344,15 +344,15 @@ static int has_unstaged_changes(const char *prefix)
344344
/**
345345
* Returns 1 if there are uncommitted changes, 0 otherwise.
346346
*/
347-
static int has_uncommitted_changes(const char *prefix)
347+
static int has_uncommitted_changes(void)
348348
{
349349
struct rev_info rev_info;
350350
int result;
351351

352352
if (is_cache_unborn())
353353
return 0;
354354

355-
init_revisions(&rev_info, prefix);
355+
init_revisions(&rev_info, NULL);
356356
DIFF_OPT_SET(&rev_info.diffopt, IGNORE_SUBMODULES);
357357
DIFF_OPT_SET(&rev_info.diffopt, QUICK);
358358
add_head_to_pending(&rev_info);
@@ -365,7 +365,7 @@ static int has_uncommitted_changes(const char *prefix)
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(const char *prefix)
368+
static void die_on_unclean_work_tree(void)
369369
{
370370
struct lock_file *lock_file = xcalloc(1, sizeof(*lock_file));
371371
int do_die = 0;
@@ -375,12 +375,12 @@ static void die_on_unclean_work_tree(const char *prefix)
375375
update_index_if_able(&the_index, lock_file);
376376
rollback_lock_file(lock_file);
377377

378-
if (has_unstaged_changes(prefix)) {
378+
if (has_unstaged_changes()) {
379379
error(_("Cannot pull with rebase: You have unstaged changes."));
380380
do_die = 1;
381381
}
382382

383-
if (has_uncommitted_changes(prefix)) {
383+
if (has_uncommitted_changes()) {
384384
if (do_die)
385385
error(_("Additionally, your index contains uncommitted changes."));
386386
else
@@ -875,7 +875,7 @@ int cmd_pull(int argc, const char **argv, const char *prefix)
875875
die(_("Updating an unborn branch with changes added to the index."));
876876

877877
if (!autostash)
878-
die_on_unclean_work_tree(prefix);
878+
die_on_unclean_work_tree();
879879

880880
if (get_rebase_fork_point(rebase_fork_point, repo, *refspecs))
881881
hashclr(rebase_fork_point);

0 commit comments

Comments
 (0)