Skip to content

Commit

Permalink
cli: git push: borrow repo from transaction
Browse files Browse the repository at this point in the history
This forces us to think about which repo should be used. It doesn't matter in
find_bookmarks_to_push() because moved "push-{change_id}" bookmarks are
prioritized. It doesn't matter in print_commits_ready_to_push() either, which
uses the repo only for ancestry lookup, but I think tx.repo() is better here.
  • Loading branch information
yuja committed Nov 15, 2024
1 parent 5a793f6 commit 7ed829e
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions cli/src/commands/git/push.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,12 +161,12 @@ pub fn cmd_git_push(
get_default_push_remote(ui, command.settings(), &git_repo)?
};

let repo = workspace_command.repo().clone();
let mut tx = workspace_command.start_transaction();
let view = tx.repo().view();
let tx_description;
let mut bookmark_updates = vec![];
if args.all {
for (bookmark_name, targets) in repo.view().local_remote_bookmarks(&remote) {
for (bookmark_name, targets) in view.local_remote_bookmarks(&remote) {
match classify_bookmark_update(bookmark_name, &remote, targets) {
Ok(Some(update)) => bookmark_updates.push((bookmark_name.to_owned(), update)),
Ok(None) => {}
Expand All @@ -175,7 +175,7 @@ pub fn cmd_git_push(
}
tx_description = format!("push all bookmarks to git remote {remote}");
} else if args.tracked {
for (bookmark_name, targets) in repo.view().local_remote_bookmarks(&remote) {
for (bookmark_name, targets) in view.local_remote_bookmarks(&remote) {
if !targets.remote_ref.is_tracking() {
continue;
}
Expand All @@ -187,7 +187,7 @@ pub fn cmd_git_push(
}
tx_description = format!("push all tracked bookmarks to git remote {remote}");
} else if args.deleted {
for (bookmark_name, targets) in repo.view().local_remote_bookmarks(&remote) {
for (bookmark_name, targets) in view.local_remote_bookmarks(&remote) {
if targets.local_target.is_present() {
continue;
}
Expand Down Expand Up @@ -222,7 +222,8 @@ pub fn cmd_git_push(
};
(bookmark_name.as_ref(), targets)
});
let bookmarks_by_name = find_bookmarks_to_push(repo.view(), &args.bookmark, &remote)?;
let view = tx.repo().view();
let bookmarks_by_name = find_bookmarks_to_push(view, &args.bookmark, &remote)?;
for (bookmark_name, targets) in change_bookmarks.chain(bookmarks_by_name.iter().copied()) {
if !seen_bookmarks.insert(bookmark_name) {
continue;
Expand Down Expand Up @@ -276,7 +277,7 @@ pub fn cmd_git_push(
validate_commits_ready_to_push(ui, &bookmark_updates, &remote, &tx, command, args)?;
if let Some(mut formatter) = ui.status_formatter() {
writeln!(formatter, "Changes to push to {remote}:")?;
print_commits_ready_to_push(formatter.as_mut(), repo.as_ref(), &bookmark_updates)?;
print_commits_ready_to_push(formatter.as_mut(), tx.repo(), &bookmark_updates)?;
}

if args.dry_run {
Expand Down

0 comments on commit 7ed829e

Please sign in to comment.