Fix staging error reporting (#25630)
Closes #ISSUE Release Notes: - N/A
This commit is contained in:
parent
089ea5da50
commit
b2a685f00a
3 changed files with 40 additions and 24 deletions
|
@ -7709,7 +7709,15 @@ impl Editor {
|
||||||
for hunk in &hunks {
|
for hunk in &hunks {
|
||||||
self.prepare_restore_change(&mut revert_changes, hunk, cx);
|
self.prepare_restore_change(&mut revert_changes, hunk, cx);
|
||||||
}
|
}
|
||||||
Self::do_stage_or_unstage(project, false, buffer_id, hunks.into_iter(), &snapshot, cx);
|
Self::do_stage_or_unstage(
|
||||||
|
project,
|
||||||
|
false,
|
||||||
|
buffer_id,
|
||||||
|
hunks.into_iter(),
|
||||||
|
&snapshot,
|
||||||
|
window,
|
||||||
|
cx,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
drop(chunk_by);
|
drop(chunk_by);
|
||||||
if !revert_changes.is_empty() {
|
if !revert_changes.is_empty() {
|
||||||
|
@ -13424,13 +13432,13 @@ impl Editor {
|
||||||
pub fn toggle_staged_selected_diff_hunks(
|
pub fn toggle_staged_selected_diff_hunks(
|
||||||
&mut self,
|
&mut self,
|
||||||
_: &::git::ToggleStaged,
|
_: &::git::ToggleStaged,
|
||||||
_window: &mut Window,
|
window: &mut Window,
|
||||||
cx: &mut Context<Self>,
|
cx: &mut Context<Self>,
|
||||||
) {
|
) {
|
||||||
let snapshot = self.buffer.read(cx).snapshot(cx);
|
let snapshot = self.buffer.read(cx).snapshot(cx);
|
||||||
let ranges: Vec<_> = self.selections.disjoint.iter().map(|s| s.range()).collect();
|
let ranges: Vec<_> = self.selections.disjoint.iter().map(|s| s.range()).collect();
|
||||||
let stage = self.has_stageable_diff_hunks_in_ranges(&ranges, &snapshot);
|
let stage = self.has_stageable_diff_hunks_in_ranges(&ranges, &snapshot);
|
||||||
self.stage_or_unstage_diff_hunks(stage, &ranges, cx);
|
self.stage_or_unstage_diff_hunks(stage, &ranges, window, cx);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn stage_and_next(
|
pub fn stage_and_next(
|
||||||
|
@ -13455,6 +13463,7 @@ impl Editor {
|
||||||
&mut self,
|
&mut self,
|
||||||
stage: bool,
|
stage: bool,
|
||||||
ranges: &[Range<Anchor>],
|
ranges: &[Range<Anchor>],
|
||||||
|
window: &mut Window,
|
||||||
cx: &mut Context<Self>,
|
cx: &mut Context<Self>,
|
||||||
) {
|
) {
|
||||||
let snapshot = self.buffer.read(cx).snapshot(cx);
|
let snapshot = self.buffer.read(cx).snapshot(cx);
|
||||||
|
@ -13466,7 +13475,7 @@ impl Editor {
|
||||||
.diff_hunks_in_ranges(&ranges, &snapshot)
|
.diff_hunks_in_ranges(&ranges, &snapshot)
|
||||||
.chunk_by(|hunk| hunk.buffer_id);
|
.chunk_by(|hunk| hunk.buffer_id);
|
||||||
for (buffer_id, hunks) in &chunk_by {
|
for (buffer_id, hunks) in &chunk_by {
|
||||||
Self::do_stage_or_unstage(project, stage, buffer_id, hunks, &snapshot, cx);
|
Self::do_stage_or_unstage(project, stage, buffer_id, hunks, &snapshot, window, cx);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -13478,7 +13487,7 @@ impl Editor {
|
||||||
) {
|
) {
|
||||||
let mut ranges = self.selections.disjoint_anchor_ranges().collect::<Vec<_>>();
|
let mut ranges = self.selections.disjoint_anchor_ranges().collect::<Vec<_>>();
|
||||||
if ranges.iter().any(|range| range.start != range.end) {
|
if ranges.iter().any(|range| range.start != range.end) {
|
||||||
self.stage_or_unstage_diff_hunks(stage, &ranges[..], cx);
|
self.stage_or_unstage_diff_hunks(stage, &ranges[..], window, cx);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -13521,7 +13530,7 @@ impl Editor {
|
||||||
buffer.read(cx).remote_id(),
|
buffer.read(cx).remote_id(),
|
||||||
range,
|
range,
|
||||||
)];
|
)];
|
||||||
self.stage_or_unstage_diff_hunks(stage, &ranges[..], cx);
|
self.stage_or_unstage_diff_hunks(stage, &ranges[..], window, cx);
|
||||||
let snapshot = self.buffer().read(cx).snapshot(cx);
|
let snapshot = self.buffer().read(cx).snapshot(cx);
|
||||||
let mut point = ranges.last().unwrap().end.to_point(&snapshot);
|
let mut point = ranges.last().unwrap().end.to_point(&snapshot);
|
||||||
if point.row < snapshot.max_row().0 {
|
if point.row < snapshot.max_row().0 {
|
||||||
|
@ -13535,7 +13544,7 @@ impl Editor {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
self.stage_or_unstage_diff_hunks(stage, &ranges[..], cx);
|
self.stage_or_unstage_diff_hunks(stage, &ranges[..], window, cx);
|
||||||
self.go_to_next_hunk(&Default::default(), window, cx);
|
self.go_to_next_hunk(&Default::default(), window, cx);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -13545,6 +13554,7 @@ impl Editor {
|
||||||
buffer_id: BufferId,
|
buffer_id: BufferId,
|
||||||
hunks: impl Iterator<Item = MultiBufferDiffHunk>,
|
hunks: impl Iterator<Item = MultiBufferDiffHunk>,
|
||||||
snapshot: &MultiBufferSnapshot,
|
snapshot: &MultiBufferSnapshot,
|
||||||
|
window: &mut Window,
|
||||||
cx: &mut App,
|
cx: &mut App,
|
||||||
) {
|
) {
|
||||||
let Some(buffer) = project.read(cx).buffer_for_id(buffer_id, cx) else {
|
let Some(buffer) = project.read(cx).buffer_for_id(buffer_id, cx) else {
|
||||||
|
@ -13587,20 +13597,18 @@ impl Editor {
|
||||||
cx,
|
cx,
|
||||||
)
|
)
|
||||||
};
|
};
|
||||||
|
|
||||||
if file_exists {
|
if file_exists {
|
||||||
let buffer_store = project.read(cx).buffer_store().clone();
|
let buffer_store = project.read(cx).buffer_store().clone();
|
||||||
buffer_store
|
buffer_store
|
||||||
.update(cx, |buffer_store, cx| buffer_store.save_buffer(buffer, cx))
|
.update(cx, |buffer_store, cx| buffer_store.save_buffer(buffer, cx))
|
||||||
.detach_and_log_err(cx);
|
.detach_and_log_err(cx);
|
||||||
}
|
}
|
||||||
|
let recv = repo
|
||||||
|
.read(cx)
|
||||||
|
.set_index_text(&path, new_index_text.map(|rope| rope.to_string()));
|
||||||
|
|
||||||
cx.background_spawn(
|
cx.background_spawn(async move { recv.await? })
|
||||||
repo.read(cx)
|
.detach_and_notify_err(window, cx);
|
||||||
.set_index_text(&path, new_index_text.map(|rope| rope.to_string()))
|
|
||||||
.log_err(),
|
|
||||||
)
|
|
||||||
.detach();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn expand_selected_diff_hunks(&mut self, cx: &mut Context<Self>) {
|
pub fn expand_selected_diff_hunks(&mut self, cx: &mut Context<Self>) {
|
||||||
|
|
|
@ -8720,11 +8720,12 @@ fn diff_hunk_controls(
|
||||||
})
|
})
|
||||||
.on_click({
|
.on_click({
|
||||||
let editor = editor.clone();
|
let editor = editor.clone();
|
||||||
move |_event, _, cx| {
|
move |_event, window, cx| {
|
||||||
editor.update(cx, |editor, cx| {
|
editor.update(cx, |editor, cx| {
|
||||||
editor.stage_or_unstage_diff_hunks(
|
editor.stage_or_unstage_diff_hunks(
|
||||||
false,
|
false,
|
||||||
&[hunk_range.start..hunk_range.start],
|
&[hunk_range.start..hunk_range.start],
|
||||||
|
window,
|
||||||
cx,
|
cx,
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
@ -8749,11 +8750,12 @@ fn diff_hunk_controls(
|
||||||
})
|
})
|
||||||
.on_click({
|
.on_click({
|
||||||
let editor = editor.clone();
|
let editor = editor.clone();
|
||||||
move |_event, _, cx| {
|
move |_event, window, cx| {
|
||||||
editor.update(cx, |editor, cx| {
|
editor.update(cx, |editor, cx| {
|
||||||
editor.stage_or_unstage_diff_hunks(
|
editor.stage_or_unstage_diff_hunks(
|
||||||
true,
|
true,
|
||||||
&[hunk_range.start..hunk_range.start],
|
&[hunk_range.start..hunk_range.start],
|
||||||
|
window,
|
||||||
cx,
|
cx,
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
|
@ -358,24 +358,30 @@ impl GitRepository for RealGitRepository {
|
||||||
|
|
||||||
log::debug!("indexing SHA: {sha}, path {path:?}");
|
log::debug!("indexing SHA: {sha}, path {path:?}");
|
||||||
|
|
||||||
let status = new_std_command(&self.git_binary_path)
|
let output = new_std_command(&self.git_binary_path)
|
||||||
.current_dir(&working_directory)
|
.current_dir(&working_directory)
|
||||||
.args(["update-index", "--add", "--cacheinfo", "100644", &sha])
|
.args(["update-index", "--add", "--cacheinfo", "100644", &sha])
|
||||||
.arg(path.as_ref())
|
.arg(path.as_ref())
|
||||||
.status()?;
|
.output()?;
|
||||||
|
|
||||||
if !status.success() {
|
if !output.status.success() {
|
||||||
return Err(anyhow!("Failed to add to index: {status:?}"));
|
return Err(anyhow!(
|
||||||
|
"Failed to stage:\n{}",
|
||||||
|
String::from_utf8_lossy(&output.stderr)
|
||||||
|
));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
let status = new_std_command(&self.git_binary_path)
|
let output = new_std_command(&self.git_binary_path)
|
||||||
.current_dir(&working_directory)
|
.current_dir(&working_directory)
|
||||||
.args(["update-index", "--force-remove"])
|
.args(["update-index", "--force-remove"])
|
||||||
.arg(path.as_ref())
|
.arg(path.as_ref())
|
||||||
.status()?;
|
.output()?;
|
||||||
|
|
||||||
if !status.success() {
|
if !output.status.success() {
|
||||||
return Err(anyhow!("Failed to remove from index: {status:?}"));
|
return Err(anyhow!(
|
||||||
|
"Failed to unstage:\n{}",
|
||||||
|
String::from_utf8_lossy(&output.stderr)
|
||||||
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue