Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 12 additions & 10 deletions git-branchless/src/commands/submit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,16 +184,18 @@ These remotes are available: {}",
pushed_branches.extend(branches_to_push_names.iter());
skipped_branches.extend(branches_to_skip_names.iter());

let mut args = vec!["push", "--force-with-lease", remote_name];
args.extend(branches_to_push_names.iter());
let exit_code = git_run_info.run(&effects, Some(event_tx_id), &args)?;
if !exit_code.is_success() {
writeln!(
effects.get_output_stream(),
"Failed to push branches: {}",
branches_to_push_names.into_iter().join(", ")
)?;
return Ok(exit_code);
if !pushed_branches.is_empty() {
let mut args = vec!["push", "--force-with-lease", remote_name];
args.extend(branches_to_push_names.iter());
let exit_code = git_run_info.run(&effects, Some(event_tx_id), &args)?;
if !exit_code.is_success() {
writeln!(
effects.get_output_stream(),
"Failed to push branches: {}",
branches_to_push_names.into_iter().join(", ")
)?;
return Ok(exit_code);
}
}
progress.notify_progress_inc(branches.len());
}
Expand Down
62 changes: 57 additions & 5 deletions git-branchless/tests/command/test_submit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,13 +113,9 @@ fn test_submit() -> eyre::Result<()> {
{
let (stdout, stderr) = cloned_repo.run(&["submit", "--create"])?;
let stderr = redact_remotes(stderr);
insta::assert_snapshot!(stderr, @r###"
branchless: processing 1 update: remote branch origin/qux
Everything up-to-date
"###);
insta::assert_snapshot!(stderr, @"");
insta::assert_snapshot!(stdout, @r###"
branchless: running command: <git-executable> fetch origin
branchless: running command: <git-executable> push --force-with-lease origin
Skipped 2 branches (already up-to-date): bar, qux
"###);
}
Expand Down Expand Up @@ -240,3 +236,59 @@ fn test_submit_existing_branch() -> eyre::Result<()> {

Ok(())
}

#[test]
fn test_submit_up_to_date_branch() -> eyre::Result<()> {
let GitWrapperWithRemoteRepo {
temp_dir: _guard,
original_repo,
cloned_repo,
} = make_git_with_remote_repo()?;

if original_repo.get_version()? < MIN_VERSION {
return Ok(());
}

{
original_repo.init_repo()?;
original_repo.commit_file("test1", 1)?;
original_repo.commit_file("test2", 2)?;
original_repo.clone_repo_into(&cloned_repo, &[])?;
cloned_repo.init_repo_with_options(&GitInitOptions {
make_initial_commit: false,
..Default::default()
})?;
}

cloned_repo.run(&["checkout", "-b", "feature"])?;
cloned_repo.commit_file("test3", 3)?;

{
let (stdout, stderr) = cloned_repo.run(&["submit", "--create", "feature"])?;
let stderr = redact_remotes(stderr);
insta::assert_snapshot!(stderr, @r###"
branchless: processing 1 update: branch feature
To: file://<remote>
* [new branch] feature -> feature
branchless: processing 1 update: remote branch origin/feature
"###);
insta::assert_snapshot!(stdout, @r###"
branchless: running command: <git-executable> push --set-upstream origin feature
branch 'feature' set up to track 'origin/feature'.
Created 1 branch: feature
"###);
}

cloned_repo.detach_head()?;
{
let (stdout, stderr) = cloned_repo.run(&["submit", "feature"])?;
let stderr = redact_remotes(stderr);
insta::assert_snapshot!(stderr, @"");
insta::assert_snapshot!(stdout, @r###"
branchless: running command: <git-executable> fetch origin
Skipped 1 branch (already up-to-date): feature
"###);
}

Ok(())
}