Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[RFR] fix ssc default behavior : must use base branch comparison when no optional args are provided #42

Merged
merged 1 commit into from
Sep 3, 2024
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
2 changes: 0 additions & 2 deletions src/cli.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use std::env::current_dir;
use std::path::PathBuf;
use clap::Parser;
use clap::builder::NonEmptyStringValueParser;
use clap::ArgAction::Count;

// RawCli represents the CLI args and options as passed on a shell.
Expand Down Expand Up @@ -33,7 +32,6 @@ struct RawCli {
visible_alias = "base-tag",
conflicts_with = "base_branch",
default_value = "",
value_parser = NonEmptyStringValueParser::new(),
long_help = "The ref (i.e. commit or tag) from where to look for changes. Not usable with `base-branch` arg.",
)]
base_ref: String,
Expand Down
14 changes: 12 additions & 2 deletions src/git/commits_range.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use std::path::PathBuf;
use super::branch::get_current_branch;
use super::branch::get_current_remote;
use super::branch::get_merge_base_commit;
use log::debug;

pub struct CommitsRange {
from: String,
Expand Down Expand Up @@ -42,15 +43,24 @@ fn resolve_start_ref(
base_branch: &String,
base_ref: &String,
) -> String {
let start_ref: String;

if !base_ref.is_empty() {
return base_ref.to_string();
start_ref = base_ref.to_string();
debug!("CommitsRange : Using base ref as start ref ({}).", &start_ref);

return start_ref;
}

return resolve_base_branch_start_ref(
start_ref = resolve_base_branch_start_ref(
&working_directory,
remote,
base_branch,
);

debug!("CommitsRange : Using base branch as start ref ({}).", &start_ref);

return start_ref;
}

fn resolve_base_branch_start_ref(
Expand Down