Skip to content
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
6 changes: 6 additions & 0 deletions Backend/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,12 @@ fn build_invoke_handler<R: tauri::Runtime>() -> impl Fn(tauri::ipc::Invoke<R>) -
tauri_commands::git_list_branches,
tauri_commands::git_status,
tauri_commands::git_log,
tauri_commands::git_stash_list,
tauri_commands::git_stash_push,
tauri_commands::git_stash_apply,
tauri_commands::git_stash_pop,
tauri_commands::git_stash_drop,
tauri_commands::git_stash_show,
tauri_commands::git_head_status,
tauri_commands::git_checkout_branch,
tauri_commands::git_create_branch,
Expand Down
87 changes: 86 additions & 1 deletion Backend/src/tauri_commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use crate::state::AppState;
use crate::utilities::utilities;
use crate::validate;

use openvcs_core::{OnEvent, models::{BranchItem, StatusPayload, CommitItem}, Repo, BackendId, backend_id};
use openvcs_core::{OnEvent, models::{BranchItem, StatusPayload, CommitItem, StashItem}, Repo, BackendId, backend_id};
use serde::Serialize;
use openvcs_core::backend_descriptor::{get_backend, list_backends};
use openvcs_core::models::{VcsEvent};
Expand Down Expand Up @@ -376,6 +376,91 @@ pub fn git_log(
vcs.log_commits(&q).map_err(|e| e.to_string())
}

/* ---------- stash ---------- */
#[tauri::command]
pub fn git_stash_list(state: State<'_, AppState>) -> Result<Vec<StashItem>, String> {
let repo = state
.current_repo()
.ok_or_else(|| "No repository selected".to_string())?;
match repo.inner().stash_list() {
Ok(items) => {
info!("git_stash_list: count={}", items.len());
for item in &items {
info!(
"git_stash_list: selector='{}' msg='{}' meta='{}'",
item.selector,
item.msg,
item.meta
);
}
Ok(items)
}
Err(e) => {
error!("git_stash_list: failed: {}", e);
Err(e.to_string())
}
}
}

#[tauri::command]
pub fn git_stash_push(
state: State<'_, AppState>,
message: Option<String>,
include_untracked: Option<bool>,
paths: Option<Vec<String>>,
) -> Result<(), String> {
let repo = state
.current_repo()
.ok_or_else(|| "No repository selected".to_string())?;
let msg = message.unwrap_or_else(|| "WIP".to_string());
let iu = include_untracked.unwrap_or(true);
let pathbufs: Vec<std::path::PathBuf> = paths.unwrap_or_default().into_iter().map(|s| s.into()).collect();
repo.inner().stash_push(&msg, iu, &pathbufs).map_err(|e| e.to_string())
}

#[tauri::command]
pub fn git_stash_apply(state: State<'_, AppState>, selector: Option<String>) -> Result<(), String> {
let repo = state
.current_repo()
.ok_or_else(|| "No repository selected".to_string())?;
repo.inner().stash_apply(selector.unwrap_or_default().as_str()).map_err(|e| e.to_string())
}

#[tauri::command]
pub fn git_stash_pop(state: State<'_, AppState>, selector: Option<String>) -> Result<(), String> {
let repo = state
.current_repo()
.ok_or_else(|| "No repository selected".to_string())?;
repo.inner().stash_pop(selector.unwrap_or_default().as_str()).map_err(|e| e.to_string())
}

#[tauri::command]
pub fn git_stash_drop(state: State<'_, AppState>, selector: Option<String>) -> Result<(), String> {
let repo = state
.current_repo()
.ok_or_else(|| "No repository selected".to_string())?;
let selector = selector.unwrap_or_default();
info!("git_stash_drop: selector='{}'", selector);
match repo.inner().stash_drop(selector.as_str()) {
Ok(()) => {
info!("git_stash_drop: success selector='{}'", selector);
Ok(())
}
Err(e) => {
error!("git_stash_drop: failed selector='{}': {}", selector, e);
Err(e.to_string())
}
}
}

#[tauri::command]
pub fn git_stash_show(state: State<'_, AppState>, selector: Option<String>) -> Result<Vec<String>, String> {
let repo = state
.current_repo()
.ok_or_else(|| "No repository selected".to_string())?;
repo.inner().stash_show(selector.unwrap_or_default().as_str()).map_err(|e| e.to_string())
}

/* ---------- git_head_status ---------- */
#[derive(Serialize)]
pub struct HeadStatus {
Expand Down
1 change: 1 addition & 0 deletions Frontend/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
<nav class="tabs" role="tablist" aria-label="Primary views">
<button class="tab active" data-tab="changes" role="tab" aria-selected="true" id="tab-changes">Changes</button>
<button class="tab" data-tab="history" role="tab" aria-selected="false" id="tab-history">History</button>
<button class="tab" data-tab="stash" role="tab" aria-selected="false" id="tab-stash">Stash</button>
<span class="badge" id="ahead-behind" title="Divergence with upstream" aria-live="polite" hidden></span>
</nav>

Expand Down
35 changes: 35 additions & 0 deletions Frontend/src/modals/stash-confirm.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<!-- Stash confirm modal -->
<div class="modal" id="stash-confirm-modal" aria-hidden="true">
<div class="dialog sheet" role="dialog" aria-modal="true" aria-labelledby="stash-confirm-title">
<div class="sheet-head">
<div>
<h3 id="stash-confirm-title" style="margin:0">Create Stash</h3>
<p class="hint" id="stash-confirm-hint" style="margin:.25rem 0 0;">Review message and files before stashing.</p>
</div>
<button class="tbtn" data-close type="button" aria-label="Close">✕</button>
</div>
<div class="sheet-body">
<form class="panel-form" onsubmit="return false;">
<div class="group">
<label for="stash-message">Message</label>
<input id="stash-message" type="text" placeholder="e.g. WIP on feature" />
</div>
<div class="group" aria-live="polite">
<div class="input-row" style="justify-content:space-between; align-items:center;">
<label for="stash-file-list" style="margin:0;">Files to stash</label>
<span class="badge" id="stash-file-count"></span>
</div>
<div class="stash-files" id="stash-file-container" role="region">
<ul id="stash-file-list"></ul>
<p class="hint" id="stash-empty" hidden>No changes to stash.</p>
</div>
</div>
</form>
</div>
<div class="sheet-actions">
<button class="tbtn" data-close type="button">Cancel</button>
<button class="tbtn primary" id="stash-confirm-btn" type="button">Stash</button>
</div>
</div>
<div class="backdrop" data-close></div>
</div>
18 changes: 16 additions & 2 deletions Frontend/src/scripts/features/diff.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,16 @@ function buildPatchForSelectedHunks(path: string, lines: string[], hunkIndices:
// Determine file action by inspecting original diff prelude
const isAdd = prelude.some(l => l.startsWith('--- /dev/null'));
const isDel = prelude.some(l => l.startsWith('+++ /dev/null'));

// Compose minimal header (avoid carrying index/mode lines that can corrupt apply)
const headerExtras = prelude.filter((l) =>
!!l &&
!l.startsWith('diff --git') &&
!l.startsWith('--- ') &&
!l.startsWith('+++ ')
);

// Compose header and preserve any mode/index metadata Git included
let out = `diff --git a/${normPath} b/${normPath}\n`;
if (headerExtras.length) out += headerExtras.join('\n') + '\n';
if (isAdd) {
out += `--- /dev/null\n+++ b/${normPath}\n`;
} else if (isDel) {
Expand Down Expand Up @@ -142,8 +149,15 @@ function buildPatchForSelected(path: string, lines: string[], hunkIndices: numbe

const isAdd = prelude.some(l => l.startsWith('--- /dev/null'));
const isDel = prelude.some(l => l.startsWith('+++ /dev/null'));
const headerExtras = prelude.filter((l) =>
!!l &&
!l.startsWith('diff --git') &&
!l.startsWith('--- ') &&
!l.startsWith('+++ ')
);

let out = `diff --git a/${normPath} b/${normPath}\n`;
if (headerExtras.length) out += headerExtras.join('\n') + '\n';
if (isAdd) out += `--- /dev/null\n+++ b/${normPath}\n`;
else if (isDel) out += `--- a/${normPath}\n+++ /dev/null\n`;
else out += `--- a/${normPath}\n+++ b/${normPath}\n`;
Expand Down
Loading
Loading