Skip to content

Commit 7d1e364

Browse files
author
Stephan Dilly
authored
support push to origin (#266)
* use vendored ssl
1 parent 08f6735 commit 7d1e364

File tree

17 files changed

+237
-12
lines changed

17 files changed

+237
-12
lines changed

.github/workflows/cd.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ jobs:
1111
fail-fast: false
1212
matrix:
1313
os: [ubuntu-latest, macos-latest, windows-latest]
14-
1514
runs-on: ${{ matrix.os }}
15+
1616
steps:
1717
- uses: actions/checkout@v2
1818

.github/workflows/ci.yml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ jobs:
1515
matrix:
1616
os: [ubuntu-latest, macos-latest, windows-latest]
1717
rust: [nightly, stable]
18-
1918
runs-on: ${{ matrix.os }}
2019
continue-on-error: ${{ matrix.rust == 'nightly' }}
2120

@@ -54,14 +53,13 @@ jobs:
5453
build-linux-musl:
5554
runs-on: ubuntu-latest
5655
steps:
57-
- uses: actions/checkout@v2
56+
- uses: actions/checkout@master
5857
- name: Install Rust
5958
uses: actions-rs/toolchain@v1
6059
with:
6160
toolchain: stable
6261
profile: minimal
6362
target: x86_64-unknown-linux-musl
64-
6563
- name: Setup MUSL
6664
run: |
6765
sudo apt-get -qq install musl-tools
@@ -73,6 +71,9 @@ jobs:
7371
run: |
7472
make build-linux-musl-release
7573
./target/x86_64-unknown-linux-musl/release/gitui --version
74+
- name: Test
75+
run: |
76+
make test-linux-musl
7677
7778
rustfmt:
7879
name: Rustfmt

Cargo.lock

Lines changed: 47 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ build-linux-musl-debug:
3131
build-linux-musl-release:
3232
cargo build --release --target=x86_64-unknown-linux-musl --no-default-features
3333

34+
test-linux-musl:
35+
cargo test --workspace --target=x86_64-unknown-linux-musl --no-default-features
36+
3437
test:
3538
cargo test --workspace
3639

assets/vim_style_key_config.ron

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,4 +59,5 @@
5959
commit_amend: ( code: Char('A'), modifiers: ( bits: 0,),),
6060
copy: ( code: Char('y'), modifiers: ( bits: 0,),),
6161
create_branch: ( code: Char('b'), modifiers: ( bits: 0,),),
62+
push: ( code: Char('p'), modifiers: ( bits: 0,),),
6263
)

asyncgit/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ keywords = ["git"]
1313

1414
[dependencies]
1515
scopetime = { path = "../scopetime", version = "0.1" }
16-
git2 = { version = "0.13.10", default-features = false }
16+
git2 = { version = "0.13", features = ["vendored-openssl"] }
1717
rayon-core = "1.8"
1818
crossbeam-channel = "0.4"
1919
log = "0.4"

asyncgit/src/cached/branchname.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,11 @@ impl BranchName {
3232
self.fetch(current_head)
3333
}
3434

35+
///
36+
pub fn last(&self) -> Option<String> {
37+
self.last_result.as_ref().map(|last| last.1.clone())
38+
}
39+
3540
fn fetch(&mut self, head: Head) -> Result<String> {
3641
let name = sync::get_branch_name(self.repo_path.as_str())?;
3742
self.last_result = Some((head, name.clone()));

asyncgit/src/sync/mod.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ mod hooks;
1010
mod hunks;
1111
mod ignore;
1212
mod logwalker;
13+
mod remotes;
1314
mod reset;
1415
mod stash;
1516
pub mod status;
@@ -29,6 +30,9 @@ pub use hooks::{hooks_commit_msg, hooks_post_commit, HookResult};
2930
pub use hunks::{reset_hunk, stage_hunk, unstage_hunk};
3031
pub use ignore::add_to_ignore;
3132
pub use logwalker::LogWalker;
33+
pub use remotes::{
34+
fetch_origin, get_remotes, push_origin, remote_push_master,
35+
};
3236
pub use reset::{reset_stage, reset_workdir};
3337
pub use stash::{get_stashes, stash_apply, stash_drop, stash_save};
3438
pub use tags::{get_tags, CommitTags, Tags};

asyncgit/src/sync/remotes.rs

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
//!
2+
3+
use crate::{error::Result, sync::utils};
4+
use git2::{Cred, FetchOptions, PushOptions, RemoteCallbacks};
5+
use scopetime::scope_time;
6+
7+
///
8+
pub fn get_remotes(repo_path: &str) -> Result<Vec<String>> {
9+
scope_time!("get_remotes");
10+
11+
let repo = utils::repo(repo_path)?;
12+
let remotes = repo.remotes()?;
13+
let remotes: Vec<String> =
14+
remotes.iter().filter_map(|s| s).map(String::from).collect();
15+
16+
Ok(remotes)
17+
}
18+
19+
///
20+
pub fn remote_push_master(repo_path: &str) -> Result<()> {
21+
scope_time!("remote_push_master");
22+
23+
let repo = utils::repo(repo_path)?;
24+
let mut remote = repo.find_remote("origin")?;
25+
26+
remote.push(&["refs/heads/master"], None)?;
27+
28+
Ok(())
29+
}
30+
31+
///
32+
pub fn fetch_origin(repo_path: &str, branch: &str) -> Result<usize> {
33+
scope_time!("remote_fetch_master");
34+
35+
let repo = utils::repo(repo_path)?;
36+
let mut remote = repo.find_remote("origin")?;
37+
38+
let mut options = FetchOptions::new();
39+
options.remote_callbacks(remote_callbacks());
40+
41+
remote.fetch(&[branch], Some(&mut options), None)?;
42+
43+
Ok(remote.stats().received_bytes())
44+
}
45+
46+
///
47+
pub fn push_origin(repo_path: &str, branch: &str) -> Result<()> {
48+
scope_time!("push_origin");
49+
50+
let repo = utils::repo(repo_path)?;
51+
let mut remote = repo.find_remote("origin")?;
52+
53+
let mut options = PushOptions::new();
54+
options.remote_callbacks(remote_callbacks());
55+
56+
remote.push(&[branch], Some(&mut options))?;
57+
58+
Ok(())
59+
}
60+
61+
fn remote_callbacks<'a>() -> RemoteCallbacks<'a> {
62+
let mut callbacks = RemoteCallbacks::new();
63+
callbacks.credentials(|url, username_from_url, allowed_types| {
64+
log::debug!(
65+
"creds: '{}' {:?} ({:?})",
66+
url,
67+
username_from_url,
68+
allowed_types
69+
);
70+
71+
Cred::ssh_key_from_agent(
72+
username_from_url.expect("username not found"),
73+
)
74+
});
75+
76+
callbacks
77+
}
78+
79+
#[cfg(test)]
80+
mod tests {
81+
use super::*;
82+
use crate::sync::tests::debug_cmd_print;
83+
use tempfile::TempDir;
84+
85+
#[test]
86+
fn test_smoke() {
87+
let td = TempDir::new().unwrap();
88+
89+
debug_cmd_print(
90+
td.path().as_os_str().to_str().unwrap(),
91+
"git clone https://github.com/extrawurst/brewdump.git",
92+
);
93+
94+
let repo_path = td.path().join("brewdump");
95+
let repo_path = repo_path.as_os_str().to_str().unwrap();
96+
97+
let remotes = get_remotes(repo_path).unwrap();
98+
99+
assert_eq!(remotes, vec![String::from("origin")]);
100+
101+
fetch_origin(repo_path, "master").unwrap();
102+
}
103+
}

src/app.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ impl App {
256256
let msg =
257257
format!("failed to launch editor:\n{}", e);
258258
log::error!("{}", msg.as_str());
259-
self.msg.show_msg(msg.as_str())?;
259+
self.msg.show_error(msg.as_str())?;
260260
}
261261

262262
self.requires_redraw.set(true);
@@ -454,7 +454,12 @@ impl App {
454454
flags.insert(NeedsUpdate::COMMANDS);
455455
}
456456
InternalEvent::ShowErrorMsg(msg) => {
457-
self.msg.show_msg(msg.as_str())?;
457+
self.msg.show_error(msg.as_str())?;
458+
flags
459+
.insert(NeedsUpdate::ALL | NeedsUpdate::COMMANDS);
460+
}
461+
InternalEvent::ShowInfoMsg(msg) => {
462+
self.msg.show_info(msg.as_str())?;
458463
flags
459464
.insert(NeedsUpdate::ALL | NeedsUpdate::COMMANDS);
460465
}

src/clipboard.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ pub fn copy_string(_string: String) -> Result<()> {
2020
}
2121

2222
#[cfg(feature = "clipboard")]
23-
pub fn is_supported() -> bool {
23+
pub const fn is_supported() -> bool {
2424
true
2525
}
2626

src/components/changes.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,11 @@ impl ChangesComponent {
6464
Ok(())
6565
}
6666

67+
///
68+
pub fn branch_name(&self) -> Option<String> {
69+
self.branch_name.last()
70+
}
71+
6772
///
6873
pub fn set_items(&mut self, list: &[StatusItem]) -> Result<()> {
6974
self.files.update(list)?;

src/components/msg.rs

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ use tui::{
1414
use ui::style::SharedTheme;
1515

1616
pub struct MsgComponent {
17+
title: String,
1718
msg: String,
1819
visible: bool,
1920
theme: SharedTheme,
@@ -39,9 +40,7 @@ impl DrawableComponent for MsgComponent {
3940
Paragraph::new(txt.iter())
4041
.block(
4142
Block::default()
42-
.title(&strings::msg_title_error(
43-
&self.key_config,
44-
))
43+
.title(self.title.as_str())
4544
.title_style(self.theme.text_danger())
4645
.borders(Borders::ALL)
4746
.border_type(BorderType::Thick),
@@ -104,14 +103,26 @@ impl MsgComponent {
104103
key_config: SharedKeyConfig,
105104
) -> Self {
106105
Self {
106+
title: String::new(),
107107
msg: String::new(),
108108
visible: false,
109109
theme,
110110
key_config,
111111
}
112112
}
113+
114+
///
115+
pub fn show_error(&mut self, msg: &str) -> Result<()> {
116+
self.title = strings::msg_title_error(&self.key_config);
117+
self.msg = msg.to_string();
118+
self.show()?;
119+
120+
Ok(())
121+
}
122+
113123
///
114-
pub fn show_msg(&mut self, msg: &str) -> Result<()> {
124+
pub fn show_info(&mut self, msg: &str) -> Result<()> {
125+
self.title = strings::msg_title_info(&self.key_config);
115126
self.msg = msg.to_string();
116127
self.show()?;
117128

src/keys.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ pub struct KeyConfig {
6060
pub commit_amend: KeyEvent,
6161
pub copy: KeyEvent,
6262
pub create_branch: KeyEvent,
63+
pub push: KeyEvent,
6364
}
6465

6566
#[rustfmt::skip]
@@ -109,6 +110,7 @@ impl Default for KeyConfig {
109110
commit_amend: KeyEvent { code: KeyCode::Char('a'), modifiers: KeyModifiers::CONTROL},
110111
copy: KeyEvent { code: KeyCode::Char('y'), modifiers: KeyModifiers::empty()},
111112
create_branch: KeyEvent { code: KeyCode::Char('b'), modifiers: KeyModifiers::empty()},
113+
push: KeyEvent { code: KeyCode::Char('p'), modifiers: KeyModifiers::empty()},
112114
}
113115
}
114116
}

src/queue.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ pub enum InternalEvent {
3939
///
4040
ShowErrorMsg(String),
4141
///
42+
ShowInfoMsg(String),
43+
///
4244
Update(NeedsUpdate),
4345
/// open commit msg input
4446
OpenCommit,

0 commit comments

Comments
 (0)