From 3fb5077c4aaeab51018019537eb5f6526424a5de Mon Sep 17 00:00:00 2001
From: Caleb Owens
Date: Mon, 26 Aug 2024 19:23:15 +0200
Subject: [PATCH] Somethign somethign matchy matchy design
---
Cargo.lock | 15 ++
Cargo.toml | 2 +
.../src/lib/components/EditMode.svelte | 111 ++++++++++++-
apps/desktop/src/lib/modes/service.ts | 22 +++
apps/desktop/src/lib/vbranches/types.ts | 14 ++
crates/gitbutler-branch-actions/Cargo.toml | 3 +-
crates/gitbutler-branch-actions/src/file.rs | 2 +-
.../src/integration.rs | 1 +
crates/gitbutler-branch-actions/src/status.rs | 2 +-
.../gitbutler-branch-actions/src/virtual.rs | 1 +
crates/gitbutler-cherry-pick/Cargo.toml | 11 ++
crates/gitbutler-cherry-pick/src/lib.rs | 104 ++++++++++++
crates/gitbutler-diff/Cargo.toml | 3 +-
crates/gitbutler-diff/src/diff.rs | 3 +-
crates/gitbutler-edit-mode/Cargo.toml | 3 +
crates/gitbutler-edit-mode/src/commands.rs | 10 ++
crates/gitbutler-edit-mode/src/lib.rs | 156 +++++++++++++-----
crates/gitbutler-repo/Cargo.toml | 1 +
crates/gitbutler-repo/src/conflicts.rs | 36 ----
crates/gitbutler-repo/src/lib.rs | 2 -
crates/gitbutler-repo/src/rebase.rs | 51 +++---
crates/gitbutler-repo/src/repository_ext.rs | 66 +-------
crates/gitbutler-tauri/src/main.rs | 3 +-
crates/gitbutler-tauri/src/modes.rs | 12 ++
24 files changed, 460 insertions(+), 174 deletions(-)
create mode 100644 crates/gitbutler-cherry-pick/Cargo.toml
create mode 100644 crates/gitbutler-cherry-pick/src/lib.rs
delete mode 100644 crates/gitbutler-repo/src/conflicts.rs
diff --git a/Cargo.lock b/Cargo.lock
index 82984ecd1..4e8df1130 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -2140,6 +2140,7 @@ dependencies = [
"git2",
"git2-hooks",
"gitbutler-branch",
+ "gitbutler-cherry-pick",
"gitbutler-command-context",
"gitbutler-commit",
"gitbutler-diff",
@@ -2175,6 +2176,15 @@ dependencies = [
"urlencoding",
]
+[[package]]
+name = "gitbutler-cherry-pick"
+version = "0.0.0"
+dependencies = [
+ "anyhow",
+ "git2",
+ "gitbutler-commit",
+]
+
[[package]]
name = "gitbutler-cli"
version = "0.0.0"
@@ -2235,6 +2245,7 @@ dependencies = [
"bstr",
"diffy",
"git2",
+ "gitbutler-cherry-pick",
"gitbutler-command-context",
"gitbutler-serde",
"hex",
@@ -2252,14 +2263,17 @@ dependencies = [
"git2",
"gitbutler-branch",
"gitbutler-branch-actions",
+ "gitbutler-cherry-pick",
"gitbutler-command-context",
"gitbutler-commit",
+ "gitbutler-diff",
"gitbutler-operating-modes",
"gitbutler-oplog",
"gitbutler-project",
"gitbutler-reference",
"gitbutler-repo",
"gitbutler-time",
+ "serde",
]
[[package]]
@@ -2419,6 +2433,7 @@ dependencies = [
"bstr",
"git2",
"gitbutler-branch",
+ "gitbutler-cherry-pick",
"gitbutler-command-context",
"gitbutler-commit",
"gitbutler-config",
diff --git a/Cargo.toml b/Cargo.toml
index fafb23d93..12e39fd63 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -30,6 +30,7 @@ members = [
"crates/gitbutler-diff",
"crates/gitbutler-operating-modes",
"crates/gitbutler-edit-mode",
+ "crates/gitbutler-cherry-pick",
]
resolver = "2"
@@ -82,6 +83,7 @@ gitbutler-url = { path = "crates/gitbutler-url" }
gitbutler-diff = { path = "crates/gitbutler-diff" }
gitbutler-operating-modes = { path = "crates/gitbutler-operating-modes" }
gitbutler-edit-mode = { path = "crates/gitbutler-edit-mode" }
+gitbutler-cherry-pick = { path = "crates/gitbutler-cherry-pick" }
[profile.release]
codegen-units = 1 # Compile crates one after another so the compiler can optimize better
diff --git a/apps/desktop/src/lib/components/EditMode.svelte b/apps/desktop/src/lib/components/EditMode.svelte
index 6ef1d8d7a..e826004b7 100644
--- a/apps/desktop/src/lib/components/EditMode.svelte
+++ b/apps/desktop/src/lib/components/EditMode.svelte
@@ -3,9 +3,12 @@
import ProjectNameLabel from '../shared/ProjectNameLabel.svelte';
import newProjectSvg from '$lib/assets/illustrations/new-project.svg?raw';
import { Project } from '$lib/backend/projects';
- import { ModeService, type EditModeMetadata } from '$lib/modes/service';
+ import { InitialFile, ModeService, type EditModeMetadata } from '$lib/modes/service';
+ import { UncommitedFilesWatcher } from '$lib/uncommitedFiles/watcher';
import { getContext } from '$lib/utils/context';
import Button from '@gitbutler/ui/Button.svelte';
+ import FileListItem from '@gitbutler/ui/file/FileListItem.svelte';
+ import type { FileStatus } from '@gitbutler/ui/file/types';
interface Props {
editModeMetadata: EditModeMetadata;
@@ -14,10 +17,77 @@
const { editModeMetadata }: Props = $props();
const project = getContext(Project);
+ const uncommitedFileWatcher = getContext(UncommitedFilesWatcher);
const modeService = getContext(ModeService);
+ const uncommitedFiles = uncommitedFileWatcher.uncommitedFiles;
+
let modeServiceSaving = $state<'inert' | 'loading' | 'completed'>('inert');
+ let initialFiles = $state([]);
+
+ $effect(() => {
+ modeService.getInitialIndexState().then((files) => {
+ initialFiles = files;
+ });
+ });
+
+ interface FileEntry {
+ name: string;
+ path: string;
+ conflicted: boolean;
+ status?: FileStatus;
+ }
+
+ const files = $derived.by(() => {
+ const files: FileEntry[] = initialFiles.map((initialFile) => ({
+ name: initialFile.filename,
+ path: initialFile.filePath,
+ conflicted: initialFile.conflicted,
+ status: $uncommitedFiles.some(
+ (uncommitedFile) => uncommitedFile[0].path === initialFile.filePath
+ )
+ ? undefined
+ : 'D'
+ }));
+
+ console.log(initialFiles);
+
+ $uncommitedFiles.forEach((uncommitedFile) => {
+ console.log(uncommitedFile);
+ const foundFile = files.find((file) => file.path === uncommitedFile[0].path);
+
+ if (foundFile) {
+ const initialFile = initialFiles.find(
+ (initialFile) => initialFile.filePath === foundFile.path
+ )!;
+
+ // This may incorrectly be true if the file is conflicted
+ // To compensate for this, we also check if the uncommited diff
+ // has conflict markers.
+ const fileChanged = initialFile.file.hunks.some(
+ (hunk) => !uncommitedFile[0].hunks.map((hunk) => hunk.diff).includes(hunk.diff)
+ );
+
+ if (fileChanged && !uncommitedFile[0].looksConflicted) {
+ foundFile.status = 'M';
+ foundFile.conflicted = false;
+ }
+ } else {
+ files.push({
+ name: uncommitedFile[0].filename,
+ path: uncommitedFile[0].path,
+ conflicted: false,
+ status: 'A'
+ });
+ }
+ });
+
+ files.sort((a, b) => a.path.localeCompare(b.path));
+
+ return files;
+ });
+
async function abort() {
modeServiceSaving = 'loading';
@@ -51,6 +121,21 @@
actions.
+
+
+ {#each files as file}
+
+
+
+ {/each}
+
+