-
Notifications
You must be signed in to change notification settings - Fork 552
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- the typescript side drives the hook runs - some very basic tests
- Loading branch information
Showing
22 changed files
with
489 additions
and
46 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import type { Tauri } from '$lib/backend/tauri'; | ||
|
||
export type HookStatus = | ||
| { | ||
status: 'success'; | ||
} | ||
| { | ||
status: 'message'; | ||
message: string; | ||
} | ||
| { | ||
status: 'notfound'; | ||
} | ||
| { | ||
status: 'failure'; | ||
error: string; | ||
}; | ||
|
||
export class HooksService { | ||
constructor(private tauri: Tauri) {} | ||
|
||
async preCommit(projectId: string, ownership: string | undefined = undefined) { | ||
return await this.tauri.invoke<HookStatus>('pre_commit_hook', { | ||
projectId, | ||
ownership | ||
}); | ||
} | ||
|
||
async postCommit(projectId: string) { | ||
return await this.tauri.invoke<HookStatus>('post_commit_hook', { | ||
projectId | ||
}); | ||
} | ||
|
||
async message(projectId: string, message: string) { | ||
return await this.tauri.invoke<HookStatus>('message_hook', { | ||
projectId, | ||
message | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -79,4 +79,5 @@ pub use branch::{ | |
|
||
pub use integration::GITBUTLER_WORKSPACE_COMMIT_TITLE; | ||
|
||
pub mod ownership; | ||
pub mod stack; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
use std::path::PathBuf; | ||
|
||
use anyhow::{anyhow, Result}; | ||
use gitbutler_diff::{DiffByPathMap, GitHunk}; | ||
use gitbutler_stack::BranchOwnershipClaims; | ||
use itertools::Itertools; | ||
|
||
pub fn filter_hunks_by_ownership( | ||
diffs: &DiffByPathMap, | ||
ownership: &BranchOwnershipClaims, | ||
) -> Result<Vec<(PathBuf, Vec<GitHunk>)>> { | ||
ownership | ||
.claims | ||
.iter() | ||
.map(|claim| { | ||
if let Some(diff) = diffs.get(&claim.file_path) { | ||
let hunks = claim | ||
.hunks | ||
.iter() | ||
.filter_map(|claimed_hunk| { | ||
diff.hunks | ||
.iter() | ||
.find(|diff_hunk| { | ||
claimed_hunk.start == diff_hunk.new_start | ||
&& claimed_hunk.end == diff_hunk.new_start + diff_hunk.new_lines | ||
}) | ||
.cloned() | ||
}) | ||
.collect_vec(); | ||
Ok((claim.file_path.clone(), hunks)) | ||
} else { | ||
Err(anyhow!("Claim not found in workspace diff")) | ||
} | ||
}) | ||
.collect::<Result<Vec<(_, Vec<_>)>>>() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.