Skip to content

Commit

Permalink
Add the --autostash option
Browse files Browse the repository at this point in the history
  • Loading branch information
yottalogical committed Oct 6, 2024
1 parent 5b9d30e commit febe84c
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
3 changes: 3 additions & 0 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ pub struct Cli {
#[arg(long)]
pub onto: Option<String>,

#[arg(long)]
pub autostash: bool,

pub upstream: Option<String>,
pub branch: Option<String>,
}
2 changes: 2 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ fn main() -> ExitCode {
interactive,
dry_run,
onto,
autostash,
upstream,
branch,
} = Cli::parse();
Expand All @@ -24,6 +25,7 @@ fn main() -> ExitCode {
interactive,
dry_run,
onto.as_deref(),
autostash,
);

match result {
Expand Down
8 changes: 7 additions & 1 deletion src/safe_rebase.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ pub fn safe_rebase(
interactive: bool,
dry_run: bool,
onto: Option<&str>,
autostash: bool,
) -> Result<(), ()> {
// Get repo
let repo = Repository::discover(repo_path.unwrap_or(&current_dir().unwrap())).unwrap();
Expand All @@ -35,7 +36,7 @@ pub fn safe_rebase(

Ok(())
} else {
let result = rebase(&repo, &upstream, &branch, interactive, onto);
let result = rebase(&repo, &upstream, &branch, interactive, onto, autostash);

match result {
Ok(_) => {
Expand Down Expand Up @@ -219,6 +220,7 @@ fn rebase(
branch: &Branch,
interactive: bool,
onto: Option<&str>,
autostash: bool,
) -> Result<ExitStatus, ExitStatus> {
let mut args = Vec::from(["rebase"]);

Expand All @@ -231,6 +233,10 @@ fn rebase(
args.push(onto);
}

if autostash {
args.push("--autostash");
}

let upstream_id = upstream.id().to_string();
args.push(&upstream_id);
args.push(branch.name().unwrap().unwrap());
Expand Down

0 comments on commit febe84c

Please sign in to comment.