litvc 1.3.0

Lit - The agentic-first distributed version control system. A complete Git replacement designed for AI agents first and humans second.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
/// 3-Way Merge Engine
///
/// Implements recursive 3-way merge with structured conflict output.
/// Supports strategies: recursive (default), ours, theirs.
use crate::core::diff::{myers_diff, DiffOp};
use crate::core::{Object, ObjectHash, Tree, TreeEntry};
use crate::storage::ObjectStore;
use serde::{Deserialize, Serialize};
use std::collections::HashMap;

/// Merge strategy
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum MergeStrategy {
    Recursive,
    Ours,
    Theirs,
}

impl std::str::FromStr for MergeStrategy {
    type Err = String;

    fn from_str(s: &str) -> Result<Self, String> {
        match s {
            "recursive" => Ok(MergeStrategy::Recursive),
            "ours" => Ok(MergeStrategy::Ours),
            "theirs" => Ok(MergeStrategy::Theirs),
            _ => Err(format!(
                "Unknown merge strategy: '{}'. Valid: recursive, ours, theirs",
                s
            )),
        }
    }
}

/// Result of a merge operation
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct MergeResult {
    /// The merged tree (if merge succeeded or has conflicts with partial results)
    pub tree: Option<ObjectHash>,
    /// Whether the merge was a fast-forward
    pub fast_forward: bool,
    /// Whether conflicts were detected
    pub has_conflicts: bool,
    /// Per-file merge results
    pub file_results: Vec<FileMergeResult>,
    /// Strategy used
    pub strategy: String,
}

/// Per-file merge result
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct FileMergeResult {
    pub path: String,
    pub status: FileMergeStatus,
    /// Conflict regions (only present if status == Conflict)
    #[serde(skip_serializing_if = "Vec::is_empty")]
    pub conflicts: Vec<ConflictRegion>,
}

/// File-level merge status
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "lowercase")]
pub enum FileMergeStatus {
    Clean,
    Conflict,
    Added,
    Deleted,
    /// Both sides modified but auto-resolved
    AutoResolved,
}

/// A single conflict region in a file
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ConflictRegion {
    pub start_line: usize,
    pub ours: Vec<String>,
    pub theirs: Vec<String>,
    pub base: Vec<String>,
}

/// Find the common ancestor (merge base) between two commits
pub fn find_merge_base(
    store: &ObjectStore,
    commit_a: &ObjectHash,
    commit_b: &ObjectHash,
) -> Result<Option<ObjectHash>, String> {
    // BFS from both commits, first intersection is the merge base
    let mut visited_a: HashMap<String, usize> = HashMap::new();
    let mut visited_b: HashMap<String, usize> = HashMap::new();
    let mut queue_a = vec![commit_a.clone()];
    let mut queue_b = vec![commit_b.clone()];
    let mut depth = 0usize;

    // Alternating BFS from both sides
    while !queue_a.is_empty() || !queue_b.is_empty() {
        // Process queue A
        let mut next_a = Vec::new();
        for hash in &queue_a {
            let key = hash.to_string();
            if visited_b.contains_key(&key) {
                return Ok(Some(hash.clone()));
            }
            if visited_a.contains_key(&key) {
                continue;
            }
            visited_a.insert(key, depth);

            if let Ok(Object::Commit(commit)) = store.read(hash) {
                for parent in &commit.parents {
                    if !visited_a.contains_key(&parent.to_string()) {
                        next_a.push(parent.clone());
                    }
                }
            }
        }
        queue_a = next_a;

        // Process queue B
        let mut next_b = Vec::new();
        for hash in &queue_b {
            let key = hash.to_string();
            if visited_a.contains_key(&key) {
                return Ok(Some(hash.clone()));
            }
            if visited_b.contains_key(&key) {
                continue;
            }
            visited_b.insert(key, depth);

            if let Ok(Object::Commit(commit)) = store.read(hash) {
                for parent in &commit.parents {
                    if !visited_b.contains_key(&parent.to_string()) {
                        next_b.push(parent.clone());
                    }
                }
            }
        }
        queue_b = next_b;
        depth += 1;

        // Safety limit
        if depth > 10000 {
            return Err("Merge base search exceeded depth limit".to_string());
        }
    }

    Ok(None) // No common ancestor
}

/// Check if commit_a is an ancestor of commit_b (for fast-forward detection)
pub fn is_ancestor(
    store: &ObjectStore,
    ancestor: &ObjectHash,
    descendant: &ObjectHash,
) -> Result<bool, String> {
    if ancestor.to_string() == descendant.to_string() {
        return Ok(true);
    }

    let mut queue = vec![descendant.clone()];
    let mut visited = std::collections::HashSet::new();

    while let Some(hash) = queue.pop() {
        let key = hash.to_string();
        if key == ancestor.to_string() {
            return Ok(true);
        }
        if !visited.insert(key) {
            continue;
        }
        if let Ok(Object::Commit(commit)) = store.read(&hash) {
            for parent in &commit.parents {
                queue.push(parent.clone());
            }
        }
    }

    Ok(false)
}

/// Perform a 3-way merge between two trees with a common base
pub fn merge_trees(
    store: &ObjectStore,
    base_tree: Option<&Tree>,
    ours_tree: &Tree,
    theirs_tree: &Tree,
    strategy: MergeStrategy,
) -> Result<MergeResult, String> {
    // Collect files from all three trees
    let base_files = match base_tree {
        Some(t) => crate::core::diff::collect_tree_files(t, store, "")?,
        None => vec![],
    };
    let ours_files = crate::core::diff::collect_tree_files(ours_tree, store, "")?;
    let theirs_files = crate::core::diff::collect_tree_files(theirs_tree, store, "")?;

    let base_map: HashMap<String, ObjectHash> = base_files.into_iter().collect();
    let ours_map: HashMap<String, ObjectHash> = ours_files.into_iter().collect();
    let theirs_map: HashMap<String, ObjectHash> = theirs_files.into_iter().collect();

    // Collect all file paths
    let mut all_paths: Vec<String> = ours_map
        .keys()
        .chain(theirs_map.keys())
        .chain(base_map.keys())
        .cloned()
        .collect();
    all_paths.sort();
    all_paths.dedup();

    let mut file_results = Vec::new();
    let mut merged_entries: Vec<(String, ObjectHash)> = Vec::new();
    let mut has_conflicts = false;

    for path in &all_paths {
        let base_hash = base_map.get(path);
        let ours_hash = ours_map.get(path);
        let theirs_hash = theirs_map.get(path);

        let result = merge_file_entry(store, path, base_hash, ours_hash, theirs_hash, strategy)?;

        if result.status == FileMergeStatus::Conflict {
            has_conflicts = true;
        }

        // Determine which hash to use in the merged tree
        match result.status {
            FileMergeStatus::Clean | FileMergeStatus::AutoResolved => {
                // Use theirs if only theirs changed, ours otherwise
                if let Some(h) = ours_hash {
                    if base_hash.map(|b| b == h).unwrap_or(false) {
                        // Ours unchanged from base, use theirs
                        if let Some(th) = theirs_hash {
                            merged_entries.push((path.clone(), th.clone()));
                        }
                    } else {
                        merged_entries.push((path.clone(), h.clone()));
                    }
                } else if let Some(th) = theirs_hash {
                    merged_entries.push((path.clone(), th.clone()));
                }
            }
            FileMergeStatus::Added => {
                if let Some(h) = ours_hash.or(theirs_hash) {
                    merged_entries.push((path.clone(), h.clone()));
                }
            }
            FileMergeStatus::Deleted => {
                // Don't include in merged tree
            }
            FileMergeStatus::Conflict => {
                // For conflicts with strategy override, pick accordingly
                match strategy {
                    MergeStrategy::Ours => {
                        if let Some(h) = ours_hash {
                            merged_entries.push((path.clone(), h.clone()));
                        }
                    }
                    MergeStrategy::Theirs => {
                        if let Some(h) = theirs_hash {
                            merged_entries.push((path.clone(), h.clone()));
                        }
                    }
                    MergeStrategy::Recursive => {
                        // Keep ours version in tree, conflicts recorded separately
                        if let Some(h) = ours_hash {
                            merged_entries.push((path.clone(), h.clone()));
                        }
                    }
                }
            }
        }

        file_results.push(result);
    }

    // Build merged tree
    let tree_hash = if !has_conflicts || strategy != MergeStrategy::Recursive {
        Some(build_flat_tree(store, &merged_entries)?)
    } else {
        None // Don't create tree when there are unresolved conflicts
    };

    Ok(MergeResult {
        tree: tree_hash,
        fast_forward: false,
        has_conflicts,
        file_results,
        strategy: format!("{:?}", strategy).to_lowercase(),
    })
}

/// Merge a single file entry using 3-way merge
fn merge_file_entry(
    store: &ObjectStore,
    path: &str,
    base_hash: Option<&ObjectHash>,
    ours_hash: Option<&ObjectHash>,
    theirs_hash: Option<&ObjectHash>,
    strategy: MergeStrategy,
) -> Result<FileMergeResult, String> {
    match (base_hash, ours_hash, theirs_hash) {
        // File exists in base but not in both branches — both deleted
        (Some(_), None, None) => Ok(FileMergeResult {
            path: path.to_string(),
            status: FileMergeStatus::Deleted,
            conflicts: vec![],
        }),

        // File only in ours (added by us, not in base or theirs)
        (None, Some(_), None) => Ok(FileMergeResult {
            path: path.to_string(),
            status: FileMergeStatus::Added,
            conflicts: vec![],
        }),

        // File only in theirs (added by them)
        (None, None, Some(_)) => Ok(FileMergeResult {
            path: path.to_string(),
            status: FileMergeStatus::Added,
            conflicts: vec![],
        }),

        // File added by both — check if same content
        (None, Some(o), Some(t)) => {
            if o == t {
                Ok(FileMergeResult {
                    path: path.to_string(),
                    status: FileMergeStatus::Clean,
                    conflicts: vec![],
                })
            } else {
                handle_content_conflict(store, path, None, Some(o), Some(t), strategy)
            }
        }

        // File in base and ours, deleted by theirs
        (Some(b), Some(o), None) => {
            if o == b {
                // We didn't change it, they deleted it — accept deletion
                Ok(FileMergeResult {
                    path: path.to_string(),
                    status: FileMergeStatus::Deleted,
                    conflicts: vec![],
                })
            } else {
                // We modified, they deleted — conflict
                Ok(FileMergeResult {
                    path: path.to_string(),
                    status: FileMergeStatus::Conflict,
                    conflicts: vec![ConflictRegion {
                        start_line: 1,
                        ours: vec!["(file modified)".to_string()],
                        theirs: vec!["(file deleted)".to_string()],
                        base: vec!["(file existed)".to_string()],
                    }],
                })
            }
        }

        // File in base and theirs, deleted by ours
        (Some(b), None, Some(t)) => {
            if t == b {
                // They didn't change it, we deleted it — accept deletion
                Ok(FileMergeResult {
                    path: path.to_string(),
                    status: FileMergeStatus::Deleted,
                    conflicts: vec![],
                })
            } else {
                // They modified, we deleted — conflict
                Ok(FileMergeResult {
                    path: path.to_string(),
                    status: FileMergeStatus::Conflict,
                    conflicts: vec![ConflictRegion {
                        start_line: 1,
                        ours: vec!["(file deleted)".to_string()],
                        theirs: vec!["(file modified)".to_string()],
                        base: vec!["(file existed)".to_string()],
                    }],
                })
            }
        }

        // File in all three — standard 3-way merge
        (Some(b), Some(o), Some(t)) => {
            if o == t {
                // Both made same change (or neither changed)
                Ok(FileMergeResult {
                    path: path.to_string(),
                    status: FileMergeStatus::Clean,
                    conflicts: vec![],
                })
            } else if o == b {
                // Only theirs changed — take theirs
                Ok(FileMergeResult {
                    path: path.to_string(),
                    status: FileMergeStatus::Clean,
                    conflicts: vec![],
                })
            } else if t == b {
                // Only ours changed — take ours
                Ok(FileMergeResult {
                    path: path.to_string(),
                    status: FileMergeStatus::Clean,
                    conflicts: vec![],
                })
            } else {
                // Both changed differently — need content-level merge
                handle_content_conflict(store, path, Some(b), Some(o), Some(t), strategy)
            }
        }

        // No file anywhere (shouldn't happen)
        (None, None, None) => Ok(FileMergeResult {
            path: path.to_string(),
            status: FileMergeStatus::Clean,
            conflicts: vec![],
        }),
    }
}

/// Handle content-level conflict between two versions
fn handle_content_conflict(
    store: &ObjectStore,
    path: &str,
    base_hash: Option<&ObjectHash>,
    ours_hash: Option<&ObjectHash>,
    theirs_hash: Option<&ObjectHash>,
    strategy: MergeStrategy,
) -> Result<FileMergeResult, String> {
    // For ours/theirs strategies, no conflict
    match strategy {
        MergeStrategy::Ours => {
            return Ok(FileMergeResult {
                path: path.to_string(),
                status: FileMergeStatus::AutoResolved,
                conflicts: vec![],
            });
        }
        MergeStrategy::Theirs => {
            return Ok(FileMergeResult {
                path: path.to_string(),
                status: FileMergeStatus::AutoResolved,
                conflicts: vec![],
            });
        }
        MergeStrategy::Recursive => {}
    }

    // Read content from all versions
    let base_content = match base_hash {
        Some(h) => read_blob_text(store, h)?,
        None => String::new(),
    };
    let ours_content = match ours_hash {
        Some(h) => read_blob_text(store, h)?,
        None => String::new(),
    };
    let theirs_content = match theirs_hash {
        Some(h) => read_blob_text(store, h)?,
        None => String::new(),
    };

    // Try line-level 3-way merge
    let base_lines: Vec<&str> = base_content.lines().collect();
    let ours_lines: Vec<&str> = ours_content.lines().collect();
    let theirs_lines: Vec<&str> = theirs_content.lines().collect();

    let merge_result = three_way_merge(&base_lines, &ours_lines, &theirs_lines);

    if merge_result.conflicts.is_empty() {
        Ok(FileMergeResult {
            path: path.to_string(),
            status: FileMergeStatus::AutoResolved,
            conflicts: vec![],
        })
    } else {
        Ok(FileMergeResult {
            path: path.to_string(),
            status: FileMergeStatus::Conflict,
            conflicts: merge_result.conflicts,
        })
    }
}

/// Result of a 3-way line merge
struct ThreeWayResult {
    _merged_lines: Vec<String>,
    conflicts: Vec<ConflictRegion>,
}

/// Perform line-level 3-way merge
fn three_way_merge(base: &[&str], ours: &[&str], theirs: &[&str]) -> ThreeWayResult {
    // Diff base→ours and base→theirs using raw diff ops (no context padding)
    let ours_ops = myers_diff(base, ours);
    let theirs_ops = myers_diff(base, theirs);

    // Track which base lines each side actually modifies (removes or replaces)
    let mut ours_changed_lines: std::collections::HashSet<usize> = std::collections::HashSet::new();
    let mut theirs_changed_lines: std::collections::HashSet<usize> =
        std::collections::HashSet::new();

    {
        let mut base_idx = 0usize;
        for op in &ours_ops {
            match op {
                DiffOp::Equal(_) => {
                    base_idx += 1;
                }
                DiffOp::Delete(_) => {
                    ours_changed_lines.insert(base_idx);
                    base_idx += 1;
                }
                DiffOp::Insert(_) => {
                    ours_changed_lines.insert(base_idx);
                }
            }
        }
    }

    {
        let mut base_idx = 0usize;
        for op in &theirs_ops {
            match op {
                DiffOp::Equal(_) => {
                    base_idx += 1;
                }
                DiffOp::Delete(_) => {
                    theirs_changed_lines.insert(base_idx);
                    base_idx += 1;
                }
                DiffOp::Insert(_) => {
                    theirs_changed_lines.insert(base_idx);
                }
            }
        }
    }

    // Detect overlapping changes (conflicts)
    let mut conflicts = Vec::new();
    let overlapping: std::collections::HashSet<usize> = ours_changed_lines
        .intersection(&theirs_changed_lines)
        .cloned()
        .collect();

    if !overlapping.is_empty() {
        let mut sorted_overlaps: Vec<usize> = overlapping.into_iter().collect();
        sorted_overlaps.sort();

        let mut regions: Vec<(usize, usize)> = Vec::new();
        let mut start = sorted_overlaps[0];
        let mut end = sorted_overlaps[0];

        for &line in &sorted_overlaps[1..] {
            if line <= end + 1 {
                end = line;
            } else {
                regions.push((start, end));
                start = line;
                end = line;
            }
        }
        regions.push((start, end));

        for (start, end) in regions {
            let base_region: Vec<String> = (start..=end)
                .filter_map(|i| base.get(i).map(|s| s.to_string()))
                .collect();
            let ours_region: Vec<String> = (start..=end)
                .filter_map(|i| ours.get(i).map(|s| s.to_string()))
                .collect();
            let theirs_region: Vec<String> = (start..=end)
                .filter_map(|i| theirs.get(i).map(|s| s.to_string()))
                .collect();

            conflicts.push(ConflictRegion {
                start_line: start + 1,
                ours: ours_region,
                theirs: theirs_region,
                base: base_region,
            });
        }
    }

    // Build merged output
    let mut merged_lines = Vec::new();
    let max_len = base.len().max(ours.len()).max(theirs.len());

    for i in 0..max_len {
        if ours_changed_lines.contains(&i) && !theirs_changed_lines.contains(&i) {
            if let Some(line) = ours.get(i) {
                merged_lines.push(line.to_string());
            }
        } else if theirs_changed_lines.contains(&i) && !ours_changed_lines.contains(&i) {
            if let Some(line) = theirs.get(i) {
                merged_lines.push(line.to_string());
            }
        } else if !ours_changed_lines.contains(&i) && !theirs_changed_lines.contains(&i) {
            if let Some(line) = base.get(i) {
                merged_lines.push(line.to_string());
            }
        }
    }

    ThreeWayResult {
        _merged_lines: merged_lines,
        conflicts,
    }
}

/// Read a blob as UTF-8 text
fn read_blob_text(store: &ObjectStore, hash: &ObjectHash) -> Result<String, String> {
    match store.read(hash)? {
        Object::Blob(b) => String::from_utf8(b.content)
            .map_err(|_| format!("File {} is binary, cannot merge", hash)),
        _ => Err(format!("Expected blob object for hash {}", hash)),
    }
}

/// Build a flat tree from (path, hash) pairs
fn build_flat_tree(
    store: &ObjectStore,
    entries: &[(String, ObjectHash)],
) -> Result<ObjectHash, String> {
    // Group by top-level directory
    let mut root_entries: Vec<TreeEntry> = Vec::new();
    let mut subdirs: HashMap<String, Vec<(String, ObjectHash)>> = HashMap::new();

    for (path, hash) in entries {
        if let Some(sep) = path.find('/') {
            let dir = &path[..sep];
            let rest = &path[sep + 1..];
            subdirs
                .entry(dir.to_string())
                .or_default()
                .push((rest.to_string(), hash.clone()));
        } else {
            root_entries.push(TreeEntry {
                mode: "100644".to_string(),
                name: path.clone(),
                hash: hash.clone(),
                object_type: "blob".to_string(),
            });
        }
    }

    // Recursively build subtrees
    for (dir, sub_entries) in &subdirs {
        let subtree_hash = build_flat_tree(store, sub_entries)?;
        root_entries.push(TreeEntry {
            mode: "040000".to_string(),
            name: dir.clone(),
            hash: subtree_hash,
            object_type: "tree".to_string(),
        });
    }

    root_entries.sort_by(|a, b| a.name.cmp(&b.name));

    let tree = Tree {
        entries: root_entries,
    };
    let tree_obj = Object::Tree(tree);
    store.write(&tree_obj)
}

#[cfg(test)]
mod tests {
    use super::*;
    use std::str::FromStr;

    #[test]
    fn test_merge_strategy_from_str() {
        assert_eq!(
            MergeStrategy::from_str("recursive").unwrap(),
            MergeStrategy::Recursive
        );
        assert_eq!(
            MergeStrategy::from_str("ours").unwrap(),
            MergeStrategy::Ours
        );
        assert_eq!(
            MergeStrategy::from_str("theirs").unwrap(),
            MergeStrategy::Theirs
        );
        assert!(MergeStrategy::from_str("invalid").is_err());
    }

    #[test]
    fn test_three_way_merge_no_conflict() {
        let base = vec!["line1", "line2", "line3"];
        let ours = vec!["line1", "MODIFIED", "line3"];
        let theirs = vec!["line1", "line2", "line3"];
        let result = three_way_merge(&base, &ours, &theirs);
        assert!(result.conflicts.is_empty());
    }

    #[test]
    fn test_three_way_merge_both_sides_different_regions() {
        let base = vec!["a", "b", "c", "d", "e", "f", "g", "h", "i", "j"];
        let ours = vec!["A", "b", "c", "d", "e", "f", "g", "h", "i", "j"];
        let theirs = vec!["a", "b", "c", "d", "e", "f", "g", "h", "i", "J"];
        let result = three_way_merge(&base, &ours, &theirs);
        assert!(result.conflicts.is_empty());
        assert_eq!(
            result._merged_lines,
            vec!["A", "b", "c", "d", "e", "f", "g", "h", "i", "J"]
        );
    }

    #[test]
    fn test_three_way_merge_conflict() {
        let base = vec!["line1", "line2", "line3"];
        let ours = vec!["line1", "OURS", "line3"];
        let theirs = vec!["line1", "THEIRS", "line3"];
        let result = three_way_merge(&base, &ours, &theirs);
        assert!(!result.conflicts.is_empty());
    }
}