mirror of
https://github.com/gitbutlerapp/gitbutler.git
synced 2024-10-07 01:18:51 +03:00
Fix bug occasionally preventing hunks from being moved
- hunks equal if hash is same, regardless of line numbers - send hash from front end when updating ownership - use updated line numbers after hunk intersection match
This commit is contained in:
parent
debea8f343
commit
f2a54b7f9f
@ -26,7 +26,7 @@ impl From<&diff::GitHunk> for Hunk {
|
||||
impl PartialEq for Hunk {
|
||||
fn eq(&self, other: &Self) -> bool {
|
||||
if self.hash.is_some() && other.hash.is_some() {
|
||||
self.hash == other.hash && self.start == other.start && self.end == other.end
|
||||
self.hash == other.hash
|
||||
} else {
|
||||
self.start == other.start && self.end == other.end
|
||||
}
|
||||
@ -233,7 +233,7 @@ mod tests {
|
||||
(
|
||||
"1-2-abc".parse::<Hunk>().unwrap(),
|
||||
"2-3-abc".parse::<Hunk>().unwrap(),
|
||||
false,
|
||||
true,
|
||||
),
|
||||
(
|
||||
"1-2".parse::<Hunk>().unwrap(),
|
||||
|
@ -2071,17 +2071,19 @@ fn get_applied_status(
|
||||
.or_default()
|
||||
.insert(0, git_diff_hunk.clone());
|
||||
|
||||
let updated_hunk = Hunk {
|
||||
start: git_diff_hunk.new_start,
|
||||
end: git_diff_hunk.new_start + git_diff_hunk.new_lines,
|
||||
timestamp_ms: Some(mtime),
|
||||
hash: Some(hash.clone()),
|
||||
};
|
||||
|
||||
// remove the hunk from the current hunks because each hunk can
|
||||
// only be owned once
|
||||
git_diff_hunks.remove(i);
|
||||
|
||||
// return updated version, with new hash and/or timestamp
|
||||
return Some(
|
||||
claimed_hunk
|
||||
.clone()
|
||||
.with_timestamp(mtime)
|
||||
.with_hash(hash.as_str()),
|
||||
);
|
||||
return Some(updated_hunk);
|
||||
}
|
||||
}
|
||||
None
|
||||
|
@ -1,7 +1,9 @@
|
||||
import type { Branch, AnyFile } from './types';
|
||||
|
||||
export function filesToOwnership(files: AnyFile[]) {
|
||||
return files.map((f) => `${f.path}:${f.hunks.map(({ id }) => id).join(',')}`).join('\n');
|
||||
return files
|
||||
.map((f) => `${f.path}:${f.hunks.map(({ id, hash }) => `${id}-${hash}`).join(',')}`)
|
||||
.join('\n');
|
||||
}
|
||||
|
||||
export class Ownership {
|
||||
|
@ -19,6 +19,7 @@ export class Hunk {
|
||||
})
|
||||
modifiedAt!: Date;
|
||||
filePath!: string;
|
||||
hash?: string;
|
||||
locked!: boolean;
|
||||
lockedTo!: string | undefined;
|
||||
changeType!: ChangeType;
|
||||
@ -166,6 +167,7 @@ export class RemoteCommit {
|
||||
|
||||
export class RemoteHunk {
|
||||
diff!: string;
|
||||
hash?: string;
|
||||
|
||||
get id(): string {
|
||||
return hashCode(this.diff);
|
||||
|
Loading…
Reference in New Issue
Block a user