Skip to content

Commit

Permalink
Add branch.push_to_remote config option
Browse files Browse the repository at this point in the history
Add branch.push_to_remote config option so that users could configure
gps to push to the remote automatically any time they do a gps branch.
This is etremely useful when you are using gps locally but the team you
are working with doesn't want to use gps. I made this option default to
false.

In addition to adding this option I also renamed the command line option
to control this as well so that it matches in naming and concept.

[changelog]
added: branch.push_to_remote configuration option

<!-- ps-id: ce01645a-cecc-4103-bef2-b864e01f4730 -->
  • Loading branch information
drewdeponte committed Mar 22, 2023
1 parent 39c86b8 commit c158dda
Show file tree
Hide file tree
Showing 7 changed files with 12 additions and 8 deletions.
6 changes: 3 additions & 3 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ pub struct BranchCmdOpts {
/// Use the provided branch name instead of generating one
#[structopt(short = "n")]
pub branch_name: Option<String>,
/// Create a remote branch of the same name and push
#[structopt(short = "r")]
pub create_remote_branch: bool,
/// Push branch of the same name to the remote
#[structopt(short = "p")]
pub push_to_remote: bool,
}

#[derive(Debug, StructOpt)]
Expand Down
4 changes: 2 additions & 2 deletions src/commands/branch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ pub fn branch(
start_patch_index: usize,
end_patch_index_option: Option<usize>,
branch_name: Option<String>,
create_remote_branch: bool,
push_to_remote: bool,
color: bool,
) {
match ps::branch(
start_patch_index,
end_patch_index_option,
branch_name,
create_remote_branch,
push_to_remote,
color,
) {
Ok(_) => {}
Expand Down
2 changes: 1 addition & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ fn main() {
opts.start_patch_index,
opts.end_patch_index,
opts.branch_name,
opts.create_remote_branch,
opts.push_to_remote,
opt.color,
),
cli::Command::RequestReviewBranch(opts) => {
Expand Down
2 changes: 2 additions & 0 deletions src/ps/private/config/branch_config_dto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@ use std::option::Option;
#[derive(Debug, Deserialize, Clone, Default)]
pub struct BranchConfigDto {
pub verify_isolation: Option<bool>,
pub push_to_remote: Option<bool>,
}

impl utils::Mergable for BranchConfigDto {
/// Merge the provided b with self overriding with any present values
fn merge(&self, b: &Self) -> Self {
BranchConfigDto {
verify_isolation: b.verify_isolation.or(self.verify_isolation),
push_to_remote: b.push_to_remote.or(self.push_to_remote),
}
}
}
1 change: 1 addition & 0 deletions src/ps/private/config/get_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ fn apply_request_review_config_defaults(
fn apply_branch_config_defaults(branch_config_dto: &BranchConfigDto) -> PsBranchConfig {
PsBranchConfig {
verify_isolation: branch_config_dto.verify_isolation.unwrap_or(true),
push_to_remote: branch_config_dto.push_to_remote.unwrap_or(false),
}
}

Expand Down
1 change: 1 addition & 0 deletions src/ps/private/config/ps_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ pub struct PsRequestReviewConfig {
#[derive(Debug)]
pub struct PsBranchConfig {
pub verify_isolation: bool,
pub push_to_remote: bool,
}

#[derive(Debug)]
Expand Down
4 changes: 2 additions & 2 deletions src/ps/public/branch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ pub fn branch(
start_patch_index: usize,
end_patch_index_option: Option<usize>,
given_branch_name_option: Option<String>,
create_remote_branch: bool,
push_to_remote: bool,
color: bool,
) -> Result<(), BranchError> {
let repo = git::create_cwd_repo().map_err(BranchError::OpenRepositoryFailed)?;
Expand Down Expand Up @@ -102,7 +102,7 @@ pub fn branch(
.map_err(BranchError::CherryPickFailed)?;

// push branch up to remote branch
if create_remote_branch {
if push_to_remote || config.branch.push_to_remote {
// get remote name of current branch (e.g. origin)
let cur_branch_name =
git::get_current_branch(&repo).ok_or(BranchError::CurrentBranchNameMissing)?;
Expand Down

0 comments on commit c158dda

Please sign in to comment.