Skip to content

Commit 702562c

Browse files
author
Stephan Dilly
committed
user confirm merge (#565)
1 parent c4a8628 commit 702562c

File tree

7 files changed

+48
-23
lines changed

7 files changed

+48
-23
lines changed

CHANGELOG.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1919
- MacOS config directory now uses `~/.config/gitui` [[@remique](https://github.com/remique)] ([#317](https://github.com/extrawurst/gitui/issues/317))
2020

2121
### Added
22-
- support for pull (fetch + ff-only merge) ([#319](https://github.com/extrawurst/gitui/issues/319))
22+
- support for pull (fetch + simple merging) ([#319](https://github.com/extrawurst/gitui/issues/319))
2323
- show used char count in input texts ([#466](https://github.com/extrawurst/gitui/issues/466))
2424
- support smoother left/right toggle/keys for commit details ([#418](https://github.com/extrawurst/gitui/issues/418))
2525
- support *force push* command [[@WizardOhio24](https://github.com/WizardOhio24)] ([#274](https://github.com/extrawurst/gitui/issues/274))

asyncgit/src/sync/branch/merge_commit.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ pub fn merge_upstream_commit(
7878
Some("HEAD"),
7979
&signature,
8080
&signature,
81-
format!("Merge '{}' from {}", branch_name, remote_url)
81+
format!("Merge '{}' of {}", branch_name, remote_url)
8282
.as_str(),
8383
&tree,
8484
parents.as_slice(),
@@ -179,7 +179,7 @@ mod test {
179179
assert_eq!(
180180
details.message.unwrap().combine(),
181181
format!(
182-
"Merge 'master' from {}",
182+
"Merge 'master' of {}",
183183
r1_dir.path().to_str().unwrap()
184184
)
185185
);

src/app.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ use tui::{
3636
Frame,
3737
};
3838

39-
///
39+
/// the main app type
4040
pub struct App {
4141
do_quit: bool,
4242
help: HelpComponent,
@@ -528,6 +528,10 @@ impl App {
528528
.queue
529529
.borrow_mut()
530530
.push_back(InternalEvent::Push(branch, force)),
531+
Action::PullMerge(_) => {
532+
self.pull_popup.try_conflict_free_merge();
533+
flags.insert(NeedsUpdate::ALL);
534+
}
531535
},
532536
InternalEvent::ConfirmAction(action) => {
533537
self.reset.open(action)?;

src/components/pull.rs

+23-16
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use crate::{
55
CommandInfo, Component, DrawableComponent,
66
},
77
keys::SharedKeyConfig,
8-
queue::{InternalEvent, Queue},
8+
queue::{Action, InternalEvent, Queue},
99
strings, try_or_popup,
1010
ui::{self, style::SharedTheme},
1111
};
@@ -131,7 +131,7 @@ impl PullComponent {
131131
self.git_fetch.last_result()?
132132
{
133133
if err.is_empty() {
134-
self.do_merge()?;
134+
self.try_ff_merge()?;
135135
} else {
136136
self.queue.borrow_mut().push_back(
137137
InternalEvent::ShowErrorMsg(format!(
@@ -141,14 +141,13 @@ impl PullComponent {
141141
);
142142
}
143143
}
144-
self.hide();
145144
}
146145

147146
Ok(())
148147
}
149148

150149
// check if something is incoming and try a ff merge then
151-
fn do_merge(&self) -> Result<()> {
150+
fn try_ff_merge(&mut self) -> Result<()> {
152151
let branch_compare =
153152
sync::branch_compare_upstream(CWD, &self.branch)?;
154153
if branch_compare.behind > 0 {
@@ -157,18 +156,30 @@ impl PullComponent {
157156
&self.branch,
158157
);
159158
if let Err(err) = merge_res {
160-
log::error!("ff merge failed: {}", err);
161-
162-
try_or_popup!(
163-
self,
164-
"merge failed:",
165-
sync::merge_upstream_commit(CWD, &self.branch)
166-
);
159+
log::trace!("ff merge failed: {}", err);
160+
self.confirm_merge(branch_compare.behind);
161+
} else {
162+
self.hide();
167163
}
168164
}
169165

170166
Ok(())
171167
}
168+
169+
pub fn try_conflict_free_merge(&self) {
170+
try_or_popup!(
171+
self,
172+
"merge failed:",
173+
sync::merge_upstream_commit(CWD, &self.branch)
174+
);
175+
}
176+
177+
fn confirm_merge(&mut self, incoming: usize) {
178+
self.queue.borrow_mut().push_back(
179+
InternalEvent::ConfirmAction(Action::PullMerge(incoming)),
180+
);
181+
self.hide();
182+
}
172183
}
173184

174185
impl DrawableComponent for PullComponent {
@@ -232,7 +243,7 @@ impl Component for PullComponent {
232243

233244
fn event(&mut self, ev: Event) -> Result<bool> {
234245
if self.visible {
235-
if let Event::Key(e) = ev {
246+
if let Event::Key(_) = ev {
236247
if self.input_cred.is_visible() {
237248
if self.input_cred.event(ev)? {
238249
return Ok(true);
@@ -243,10 +254,6 @@ impl Component for PullComponent {
243254
))?;
244255
self.input_cred.hide();
245256
}
246-
} else if e == self.key_config.exit_popup
247-
&& !self.pending
248-
{
249-
self.hide();
250257
}
251258
}
252259
return Ok(true);

src/components/reset.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ impl Component for ResetComponent {
5757
_force_all: bool,
5858
) -> CommandBlocking {
5959
out.push(CommandInfo::new(
60-
strings::commands::reset_confirm(&self.key_config),
60+
strings::commands::confirm_action(&self.key_config),
6161
true,
6262
self.visible,
6363
));
@@ -169,6 +169,10 @@ impl ResetComponent {
169169
branch.rsplit('/').next().expect("There was no / in the head reference which is impossible in git"),
170170
),
171171
),
172+
Action::PullMerge(incoming) => (
173+
strings::confirm_title_merge(&self.key_config),
174+
strings::confirm_msg_merge(&self.key_config,*incoming),
175+
),
172176
};
173177
}
174178

src/queue.rs

+1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ pub enum Action {
3030
StashDrop(CommitId),
3131
DeleteBranch(String),
3232
ForcePush(String, bool),
33+
PullMerge(usize),
3334
}
3435

3536
///

src/strings.rs

+11-2
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,15 @@ pub fn confirm_title_stashdrop(
9090
) -> String {
9191
"Drop".to_string()
9292
}
93+
pub fn confirm_title_merge(_key_config: &SharedKeyConfig) -> String {
94+
"Merge".to_string()
95+
}
96+
pub fn confirm_msg_merge(
97+
_key_config: &SharedKeyConfig,
98+
incoming: usize,
99+
) -> String {
100+
format!("confirm merge of {} incoming commits? ", incoming)
101+
}
93102
pub fn confirm_msg_reset(_key_config: &SharedKeyConfig) -> String {
94103
"confirm file reset?".to_string()
95104
}
@@ -599,15 +608,15 @@ pub mod commands {
599608
CMD_GROUP_GENERAL,
600609
)
601610
}
602-
pub fn reset_confirm(
611+
pub fn confirm_action(
603612
key_config: &SharedKeyConfig,
604613
) -> CommandText {
605614
CommandText::new(
606615
format!(
607616
"Confirm [{}]",
608617
key_config.get_hint(key_config.enter),
609618
),
610-
"resets the file in question",
619+
"confirm action",
611620
CMD_GROUP_GENERAL,
612621
)
613622
}

0 commit comments

Comments
 (0)