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

Add "elsewhere" option to fetch, pull and push menu #160

Merged
merged 4 commits into from
May 2, 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
3 changes: 3 additions & 0 deletions src/default_config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ fetch_menu.--prune = ["-p"]
fetch_menu.--tags = ["-t"]
fetch_menu.fetch_all = ["a"]
fetch_menu.quit = ["q", "<esc>"]
fetch_menu.fetch_elsewhere = ["e"]

root.log_menu = ["l"]
log_menu.log_current = ["l"]
Expand All @@ -125,6 +126,7 @@ log_menu.quit = ["q", "<esc>"]
root.pull_menu = ["F"]
pull_menu.--rebase = ["-r"]
pull_menu.pull = ["p"]
pull_menu.pull_elsewhere = ["e"]
pull_menu.quit = ["q", "<esc>"]

root.push_menu = ["P"]
Expand All @@ -133,6 +135,7 @@ push_menu.--force = ["-F"]
push_menu.--no-verify = ["-h"]
push_menu.--dry-run = ["-n"]
push_menu.push = ["p"]
push_menu.push_elsewhere = ["e"]
push_menu.quit = ["q", "<esc>"]

root.rebase_menu = ["r"]
Expand Down
25 changes: 22 additions & 3 deletions src/ops/fetch.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use super::{Action, OpTrait};
use crate::{items::TargetData, menu::arg::Arg};
use super::{create_prompt, Action, OpTrait};
use crate::{items::TargetData, menu::arg::Arg, state::State, term::Term, Res};
use derive_more::Display;
use std::{process::Command, rc::Rc};
use std::{ffi::OsString, process::Command, rc::Rc};

pub(crate) const ARGS: &[Arg] = &[
Arg::new("--prune", "Prune deleted branches", false),
Expand All @@ -23,3 +23,22 @@ impl OpTrait for FetchAll {
}))
}
}

#[derive(Display)]
#[display(fmt = "Fetch from elsewhere")]
pub(crate) struct FetchElsewhere;
impl OpTrait for FetchElsewhere {
fn get_action(&self, _target: Option<&TargetData>) -> Option<Action> {
Some(create_prompt("Select remote", push_elsewhere))
}
}

fn push_elsewhere(state: &mut State, term: &mut Term, args: &[OsString], remote: &str) -> Res<()> {
let mut cmd = Command::new("git");
cmd.args(["fetch"]);
cmd.args(args);
cmd.arg(remote);

state.run_cmd_async(term, &[], cmd)?;
Ok(())
}
6 changes: 6 additions & 0 deletions src/ops/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,12 @@ pub(crate) enum Op {
Commit,
CommitAmend,
FetchAll,
FetchElsewhere,
LogCurrent,
Pull,
PullElsewhere,
Push,
PushElsewhere,
RebaseAbort,
RebaseContinue,
RebaseElsewhere,
Expand Down Expand Up @@ -126,9 +129,12 @@ impl Op {
Op::Commit => Box::new(commit::Commit),
Op::CommitAmend => Box::new(commit::CommitAmend),
Op::FetchAll => Box::new(fetch::FetchAll),
Op::FetchElsewhere => Box::new(fetch::FetchElsewhere),
Op::LogCurrent => Box::new(log::LogCurrent),
Op::Pull => Box::new(pull::Pull),
Op::PullElsewhere => Box::new(pull::PullElsewhere),
Op::Push => Box::new(push::Push),
Op::PushElsewhere => Box::new(push::PushElsewhere),
Op::RebaseAbort => Box::new(rebase::RebaseAbort),
Op::RebaseContinue => Box::new(rebase::RebaseContinue),
Op::RebaseElsewhere => Box::new(rebase::RebaseElsewhere),
Expand Down
25 changes: 22 additions & 3 deletions src/ops/pull.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use super::{Action, OpTrait};
use crate::{items::TargetData, menu::arg::Arg, state::State, term::Term};
use super::{create_prompt, Action, OpTrait};
use crate::{items::TargetData, menu::arg::Arg, state::State, term::Term, Res};
use derive_more::Display;
use std::{process::Command, rc::Rc};
use std::{ffi::OsString, process::Command, rc::Rc};

pub(crate) const ARGS: &[Arg] = &[Arg::new("--rebase", "Rebase local commits", false)];

Expand All @@ -20,3 +20,22 @@ impl OpTrait for Pull {
}))
}
}

#[derive(Display)]
#[display(fmt = "Pull from elsewhere")]
pub(crate) struct PullElsewhere;
impl OpTrait for PullElsewhere {
fn get_action(&self, _target: Option<&TargetData>) -> Option<Action> {
Some(create_prompt("Select remote", pull_elsewhere))
}
}

fn pull_elsewhere(state: &mut State, term: &mut Term, args: &[OsString], remote: &str) -> Res<()> {
let mut cmd = Command::new("git");
cmd.args(["pull"]);
cmd.args(args);
cmd.arg(remote);

state.run_cmd_async(term, &[], cmd)?;
Ok(())
}
25 changes: 22 additions & 3 deletions src/ops/push.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use super::{Action, OpTrait};
use crate::{items::TargetData, menu::arg::Arg, state::State, term::Term};
use super::{create_prompt, Action, OpTrait};
use crate::{items::TargetData, menu::arg::Arg, state::State, term::Term, Res};
use derive_more::Display;
use std::{process::Command, rc::Rc};
use std::{ffi::OsString, process::Command, rc::Rc};

pub(crate) const ARGS: &[Arg] = &[
Arg::new("--force-with-lease", "Force with lease", false),
Expand All @@ -25,3 +25,22 @@ impl OpTrait for Push {
}))
}
}

#[derive(Display)]
#[display(fmt = "Push elsewhere")]
pub(crate) struct PushElsewhere;
impl OpTrait for PushElsewhere {
fn get_action(&self, _target: Option<&TargetData>) -> Option<Action> {
Some(create_prompt("Select remote", push_elsewhere))
}
}

fn push_elsewhere(state: &mut State, term: &mut Term, args: &[OsString], remote: &str) -> Res<()> {
let mut cmd = Command::new("git");
cmd.args(["push"]);
cmd.arg(format!("--repo={}", remote));
cmd.args(args);

state.run_cmd_async(term, &[], cmd)?;
Ok(())
}
11 changes: 11 additions & 0 deletions src/tests/fetch.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
use super::*;

#[test]
fn fetch_from_elsewhere_prompt() {
snapshot!(TestContext::setup_clone(), "fe");
}

#[test]
fn fetch_from_elsewhere() {
snapshot!(TestContext::setup_clone(), "feorigin<enter>");
}
2 changes: 2 additions & 0 deletions src/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ use std::fs;
mod helpers;
mod discard;
mod editor;
mod fetch;
mod log;
mod pull;
mod push;
mod quit;
mod rebase;
Expand Down
11 changes: 11 additions & 0 deletions src/tests/pull.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
use super::*;

#[test]
fn pull_from_elsewhere_prompt() {
snapshot!(TestContext::setup_clone(), "Fe");
}

#[test]
fn pull_from_elsewhere() {
snapshot!(TestContext::setup_clone(), "Feorigin<enter>");
}
10 changes: 10 additions & 0 deletions src/tests/push.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,13 @@ fn open_push_menu_after_dash_input() {
commit(ctx.dir.path(), "new-file", "");
snapshot!(ctx, "-P");
}

#[test]
fn push_elsewhere_prompt() {
snapshot!(TestContext::setup_clone(), "Pe");
}

#[test]
fn push_elsewhere() {
snapshot!(TestContext::setup_clone(), "Peorigin<enter>");
}
25 changes: 25 additions & 0 deletions src/tests/snapshots/gitu__tests__fetch__fetch_from_elsewhere.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
---
source: src/tests/fetch.rs
expression: ctx.redact_buffer()
---
▌On branch main |
▌Your branch is up to date with 'origin/main'. |
|
Recent commits |
_______ main origin/main add initial-file |
|
|
|
|
|
|
|
|
|
|
|
|
|
────────────────────────────────────────────────────────────────────────────────|
$ git fetch origin |
styles_hash: b6d8677bf94d7533
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
---
source: src/tests/fetch.rs
expression: ctx.redact_buffer()
---
▌On branch main |
▌Your branch is up to date with 'origin/main'. |
|
Recent commits |
_______ main origin/main add initial-file |
|
|
|
|
|
|
|
|
|
|
|
|
|
────────────────────────────────────────────────────────────────────────────────|
? Select remote: › |
styles_hash: a2a72e20bfcc2997
25 changes: 25 additions & 0 deletions src/tests/snapshots/gitu__tests__pull__pull_from_elsewhere.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
---
source: src/tests/pull.rs
expression: ctx.redact_buffer()
---
▌On branch main |
▌Your branch is up to date with 'origin/main'. |
|
Recent commits |
_______ main origin/main add initial-file |
|
|
|
|
|
|
|
|
|
|
|
|
────────────────────────────────────────────────────────────────────────────────|
$ git pull origin |
Already up to date. |
styles_hash: baa329f6340fcc8b
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
---
source: src/tests/pull.rs
expression: ctx.redact_buffer()
---
▌On branch main |
▌Your branch is up to date with 'origin/main'. |
|
Recent commits |
_______ main origin/main add initial-file |
|
|
|
|
|
|
|
|
|
|
|
|
|
────────────────────────────────────────────────────────────────────────────────|
? Select remote: › |
styles_hash: a2a72e20bfcc2997
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
source: src/tests/mod.rs
source: src/tests/push.rs
expression: ctx.redact_buffer()
---
▌On branch main |
Expand All @@ -19,7 +19,7 @@ expression: ctx.redact_buffer()
────────────────────────────────────────────────────────────────────────────────|
Push Arguments |
p Push -n Dry run (--dry-run) |
q/<esc> Quit/Close -F Force (--force) |
-f Force with lease (--force-with-lease) |
e Push elsewhere -F Force (--force) |
q/<esc> Quit/Close -f Force with lease (--force-with-lease) |
-h Disable hooks (--no-verify) |
styles_hash: 4ed1a7fbfeb2affb
styles_hash: 5f1105080c8b8328
25 changes: 25 additions & 0 deletions src/tests/snapshots/gitu__tests__push__push_elsewhere.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
---
source: src/tests/push.rs
expression: ctx.redact_buffer()
---
▌On branch main |
▌Your branch is up to date with 'origin/main'. |
|
Recent commits |
_______ main origin/main add initial-file |
|
|
|
|
|
|
|
|
|
|
|
|
────────────────────────────────────────────────────────────────────────────────|
$ git push --repo=origin |
Everything up-to-date |
styles_hash: 8df49eee15f4c4d3
25 changes: 25 additions & 0 deletions src/tests/snapshots/gitu__tests__push__push_elsewhere_prompt.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
---
source: src/tests/push.rs
expression: ctx.redact_buffer()
---
▌On branch main |
▌Your branch is up to date with 'origin/main'. |
|
Recent commits |
_______ main origin/main add initial-file |
|
|
|
|
|
|
|
|
|
|
|
|
|
────────────────────────────────────────────────────────────────────────────────|
? Select remote: › |
styles_hash: a2a72e20bfcc2997