Skip to content

Add checkout file#165

Open
SandrineP wants to merge 6 commits into
QuantStack:mainfrom
SandrineP:checkout_file
Open

Add checkout file#165
SandrineP wants to merge 6 commits into
QuantStack:mainfrom
SandrineP:checkout_file

Conversation

@SandrineP

Copy link
Copy Markdown
Collaborator

Add checkout file

@codecov

codecov Bot commented Jun 2, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 84.82143% with 17 lines in your changes missing coverage. Please review.
✅ Project coverage is 86.78%. Comparing base (4bdec5e) to head (8d4fda3).
⚠️ Report is 5 commits behind head on main.

Files with missing lines Patch % Lines
src/subcommand/checkout_subcommand.cpp 84.25% 17 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #165      +/-   ##
==========================================
- Coverage   88.55%   86.78%   -1.78%     
==========================================
  Files          62       62              
  Lines        2893     2973      +80     
  Branches      361      372      +11     
==========================================
+ Hits         2562     2580      +18     
- Misses        331      393      +62     

☔ View full report in Codecov by Harness.
📢 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.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@SandrineP SandrineP marked this pull request as ready for review June 3, 2026 08:46
@ianthomas23

Copy link
Copy Markdown
Member

If you do a checkout with 2 positional arguments and the first is a branch or tag:

git2cpp checkout v1.0 v2.0

then it looks like the second argument is ignored. Should we explicitly check for this and error out rather than silently ignoring the second arg?

@JohanMabille

Copy link
Copy Markdown
Member

then it looks like the second argument is ignored. Should we explicitly check for this and error out rather than silently ignoring the second arg?

That would be consistent with git behavior.

@JohanMabille JohanMabille left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM once the error handling is added.

@ianthomas23 ianthomas23 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a couple of comments about the tests.

Comment thread test/test_checkout.py Outdated
second_file.write_text("second content")

add_cmd = [git2cpp_path, "add", "second.txt"]
subprocess.run(add_cmd, cwd=tmp_path, text=True)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should either explicitly check the returncode is zero, or add a check=True to this subprocess call.

Comment thread test/test_checkout.py Outdated
add_cmd = [git2cpp_path, "add", "second.txt"]
subprocess.run(add_cmd, cwd=tmp_path, text=True)
commit_cmd = [git2cpp_path, "commit", "-m", "Add second file"]
subprocess.run(commit_cmd, cwd=tmp_path, text=True)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Check return code here too.

Comment thread test/test_checkout.py Outdated
second_file.write_text("second content")

add_cmd = [git2cpp_path, "add", "second.txt"]
subprocess.run(add_cmd, cwd=tmp_path, text=True)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Check return code, and 2 lines below.

Comment thread src/subcommand/checkout_subcommand.cpp Outdated
}
}

void checkout_subcommand::checkout_files(

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could be renamed checkout_head_files

Comment thread src/subcommand/checkout_subcommand.cpp Outdated
throw_if_error(git_checkout_head(repo, &options));
}

void checkout_subcommand::checkout_paths(

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could be renamed checkout_tree_files or checkout_ref_files

Comment thread src/subcommand/checkout_subcommand.cpp
Comment thread src/subcommand/checkout_subcommand.cpp Outdated
Comment on lines +151 to +154
return;
}

if (!pathspecs.empty())

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prefer else if instead of multi return statements. (Early return to handle error / specific case is usually ok, but it makes it harder to nuderstand the code when used to encode the logic).

Comment thread src/subcommand/checkout_subcommand.cpp
Comment thread src/subcommand/checkout_subcommand.cpp Outdated
Comment on lines +173 to +177
return;
}
catch (const git_exception& e)

// Else treat as files
for (const auto& p : pathspecs)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here too prefer an else branch rather than a return statement.

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.

3 participants