Skip to content

Remove Branch information - #30

Merged
felixguendling merged 17 commits into
motis-project:masterfrom
aff3npirat:remove-branches
Oct 15, 2026
Merged

felixguendling merged 17 commits into
motis-project:masterfrom
aff3npirat:remove-branches

Conversation

@aff3npirat

Copy link
Copy Markdown
Contributor

No description provided.

@aff3npirat aff3npirat self-assigned this Aug 21, 2026
Comment thread src/load_deps.cc
try {
// Fetch if commit is not known.
if (!commit_exists(d, d->commit_) ||
(d->commit_ != bc.commit_ && !commit_exists(d, bc.commit_))) {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This should not be needed because if d->commit_ != commit, d->commit_ was already fetched in previous call to iterator.

Comment thread src/print_status.cc Resolved
@felixguendling

Copy link
Copy Markdown
Member

Claude review summary:

Blockers

1. Typo in the force path (src/git.cc:133)

e.exec(d->path_, "get checkout --detach");

get is not a command, so with -f every git_attach throws. motis CI runs pkg -l -h -f, so no changed dependency could be checked out. CI is green because no test exercises git_attach. A test like get_remote_test (temp repo: commit A, commit B, attach to A with and without force) would have caught it.

2. as_branch breaks on branch names containing / (src/git.cc:101)

%(refname:lstrip=-1) keeps only the last path component, so feature/foo becomes foo. The following git rev-parse foo fails and exec throws, so git_attach and print_status fail for anyone with such a local branch.

A single call gives the correct name and replaces the loop:

git for-each-ref --points-at <commit> --format=%(refname:short) refs/heads

It also fixes two smaller issues in the current loop:

  • it starts one git rev-parse process per local branch;
  • while (ss.good()) { ss >> ref; ... } (line 105) checks the last ref twice and runs rev-parse with an empty argument when there are no local branches (while (ss >> ref) would be the correct form).

Compatibility

pkg never rewrites .pkg files (dep::write_pkg_file has no callers), so existing files keep branch= and nothing breaks by itself. But every pkg version before this PR, including the current release v0.23, runs git checkout -B <branch> <remote>/<branch> after a fetch. That fails for entries without branch=. With the README example no longer showing branch=, new or edited entries will drop it, and older binaries break on them. Since CMake's find_program(pkg-bin pkg HINTS /opt/pkg) also uses any pkg on the PATH, older binaries do stick around (a CI runner had a 2021 build).

Suggestion: keep branch= in the README for now, and stop writing it in .pkg files only once everyone, including CI runners, has a release with this change.

Behaviour

  • Without -f, git checkout <target> attaches to the first local branch whose tip equals the commit, in for-each-ref order. If master and a feature branch point at the same commit, you can end up on whichever sorts first, and your next commit lands there. With -f it always detaches. I'd always detach (as git_clone does), or at least document the rule.
  • print_status.cc:44: inside if (d->referenced_commits_.size() > 1), the condition !std::all_of(..., ref.first == c) is always true.

Minor

  • dep::write_pkg_file (src/dep.cc:17) has no callers. It could be removed instead of adapted.
  • src/git.cc:2, :7: #include <fmt/base.h> sits directly after "pkg/git.h", and the boost include switches to angle brackets; both don't match the include style of the other files.
  • The CI switch to clang-format-21 isn't related to this PR. It's fine to keep, as Fix infinite fetch-loops #31's formatting check depends on it.

@felixguendling
felixguendling merged commit 56e77f6 into motis-project:master Oct 15, 2026
8 checks passed
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.

2 participants