Skip to content

fetch: add --num option to fetch the last N commits#11047

Open
miloudbelarebia wants to merge 1 commit into
treeverse:mainfrom
miloudbelarebia:fetch-num
Open

fetch: add --num option to fetch the last N commits#11047
miloudbelarebia wants to merge 1 commit into
treeverse:mainfrom
miloudbelarebia:fetch-num

Conversation

@miloudbelarebia
Copy link
Copy Markdown

Closes #11033

Problem

When merging long-lived branches, DVC can hit missing cache from earlier
commits (No such file or directory: .../xx/xxx.dir). The current workaround
is dvc fetch --all-commits, which on a branch like main can pull a huge
amount of data that isn't actually needed.

Solution

Add a --num <N> option to dvc fetch, mirroring the existing dvc gc --num:

dvc fetch --num 10
  • Used on its own, it fetches the cache for the last N commits walking back
    from the current branch's HEAD.
  • Combined with --all-branches, it applies to each branch tip (consistent
    with how num already behaves in dvc gc / brancher).
  • --num defaults to 1 (current behavior, workspace only). Values < 1
    raise InvalidArgumentError. A value larger than the available history is
    capped at the number of existing commits.

The plumbing reuses the num parameter already threaded through
Repo.brancher / iter_revs, so the change is small: thread num through
fetch() and _collect_indexes(), and expose the CLI flag.

Tests

  • tests/func/test_data_cloud.py::test_fetch_num — fetches the right number
    of commit versions for num=1/2/10.
  • tests/func/test_data_cloud.py::test_fetch_num_invalidnum=0 raises.
  • Updated tests/unit/command/test_data_sync.py::test_fetch to cover the flag.

All pass locally; ruff check / ruff format --check are clean.

Mirrors `dvc gc --num`: `dvc fetch --num N` fetches the cache for the
last N commits. On its own it walks back from the current branch's HEAD;
combined with --all-branches it applies to each branch tip.

Closes treeverse#11033
@github-project-automation github-project-automation Bot moved this to Backlog in DVC Jun 1, 2026
@CLAassistant
Copy link
Copy Markdown

CLAassistant commented Jun 1, 2026

CLA assistant check
All committers have signed the CLA.

@codecov
Copy link
Copy Markdown

codecov Bot commented Jun 1, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.98%. Comparing base (2431ec6) to head (3ab3f6a).
⚠️ Report is 204 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #11047      +/-   ##
==========================================
+ Coverage   90.68%   90.98%   +0.30%     
==========================================
  Files         504      505       +1     
  Lines       39795    41159    +1364     
  Branches     3141     3265     +124     
==========================================
+ Hits        36087    37449    +1362     
- Misses       3042     3071      +29     
+ Partials      666      639      -27     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add --num option to dvc fetch

2 participants