worktrunk 0.35.1

A CLI for Git worktree management, designed for parallel AI agent workflows
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
//! State enums for worktree and branch status.
//!
//! These represent various states a worktree or branch can be in relative to
//! the default branch, upstream remote, or git operations in progress.

use worktrunk::git::IntegrationReason;

/// Upstream divergence state relative to remote tracking branch.
///
/// Used only for upstream/remote divergence. Main branch divergence is now
/// handled by [`MainState`] which combines divergence with integration states.
///
/// | Variant   | Symbol |
/// |-----------|--------|
/// | None      | (empty) - no remote configured |
/// | InSync    | `\|`   - up-to-date with remote |
/// | Ahead     | `⇡`    - has unpushed commits   |
/// | Behind    | `⇣`    - missing remote commits |
/// | Diverged  | `⇅`    - both ahead and behind  |
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
pub enum Divergence {
    /// No remote tracking branch configured
    #[default]
    None,
    /// In sync with upstream remote
    InSync,
    /// Has commits the remote doesn't have
    Ahead,
    /// Missing commits from the remote
    Behind,
    /// Both ahead and behind the remote
    Diverged,
}

impl Divergence {
    /// Compute divergence state when a remote tracking branch exists.
    ///
    /// Returns `InSync` for 0/0 since we know a remote exists.
    /// For cases where there's no remote, use `Divergence::None` directly.
    pub fn from_counts_with_remote(ahead: usize, behind: usize) -> Self {
        match (ahead, behind) {
            (0, 0) => Self::InSync,
            (_, 0) => Self::Ahead,
            (0, _) => Self::Behind,
            _ => Self::Diverged,
        }
    }

    /// Get the display symbol for this divergence state.
    pub fn symbol(self) -> &'static str {
        match self {
            Self::None => "",
            Self::InSync => "|",
            Self::Ahead => "",
            Self::Behind => "",
            Self::Diverged => "",
        }
    }

    /// Returns styled symbol (dimmed), or None for None variant.
    pub fn styled(self) -> Option<String> {
        use color_print::cformat;
        if self == Self::None {
            None
        } else {
            Some(cformat!("<dim>{}</>", self.symbol()))
        }
    }
}

/// Worktree state indicator
///
/// Shows the "location" state of a worktree or branch:
/// - For worktrees: whether the path matches the template, or has issues
/// - For branches (without worktree): shows / to distinguish from worktrees
///
/// Priority order for worktrees: BranchWorktreeMismatch > Prunable > Locked
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default, strum::IntoStaticStr)]
pub enum WorktreeState {
    #[strum(serialize = "")]
    /// Normal worktree (path matches template, not locked or prunable)
    #[default]
    None,
    /// Branch-worktree mismatch: path doesn't match what the template would generate
    BranchWorktreeMismatch,
    /// Prunable (worktree directory missing)
    Prunable,
    /// Locked (protected from removal)
    Locked,
    /// Branch indicator (for branches without worktrees)
    Branch,
}

impl std::fmt::Display for WorktreeState {
    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
        match self {
            Self::None => Ok(()),
            Self::BranchWorktreeMismatch => write!(f, ""),
            Self::Prunable => write!(f, ""),
            Self::Locked => write!(f, ""),
            Self::Branch => write!(f, "/"),
        }
    }
}

impl serde::Serialize for WorktreeState {
    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
    where
        S: serde::Serializer,
    {
        serializer.serialize_str(&self.to_string())
    }
}

/// Default branch relationship state
///
/// Represents the combined relationship to the default branch in a single position.
/// Uses horizontal arrows (vs vertical arrows for Remote column).
///
/// Priority order determines which symbol is shown:
/// 1. IsMain (^) - this IS the main worktree
/// 2. Orphan (∅) - no common ancestor with default branch
/// 3. WouldConflict (✗) - merge-tree simulation shows conflicts
/// 4. Empty (_) - same commit as default branch AND clean working tree (safe to delete)
/// 5. SameCommit (–) - same commit as default branch with uncommitted changes
/// 6. Integrated (⊂) - content is in default branch via different history
/// 7. Diverged (↕) - both ahead and behind default branch
/// 8. Ahead (↑) - has commits default branch doesn't have
/// 9. Behind (↓) - missing commits from default branch
///
/// The `Integrated` variant carries an [`IntegrationReason`] explaining how the
/// content was integrated (ancestor, trees match, no added changes, or merge adds nothing).
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default, strum::IntoStaticStr)]
#[strum(serialize_all = "snake_case")]
pub enum MainState {
    /// Normal working branch (up-to-date with default branch, no special state)
    #[default]
    #[strum(serialize = "")]
    None,
    /// This IS the main worktree
    IsMain,
    /// Merge-tree conflicts with default branch (simulated via git merge-tree)
    WouldConflict,
    /// Branch HEAD is same commit as default branch AND working tree is clean (safe to delete)
    Empty,
    /// Branch HEAD is same commit as default branch but has uncommitted changes
    SameCommit,
    /// Content is integrated into default branch via different history
    #[strum(serialize = "integrated")]
    Integrated(IntegrationReason),
    /// No common ancestor with default branch (orphan branch)
    Orphan,
    /// Both ahead and behind default branch
    Diverged,
    /// Has commits default branch doesn't have
    Ahead,
    /// Missing commits from default branch
    Behind,
}

impl std::fmt::Display for MainState {
    /// Single-stroke vertical arrows for Main column (vs double-stroke arrows for Remote column).
    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
        match self {
            Self::None => Ok(()),
            Self::IsMain => write!(f, "^"),
            Self::WouldConflict => write!(f, ""),
            Self::Empty => write!(f, "_"),
            Self::SameCommit => write!(f, ""), // en-dash U+2013
            Self::Integrated(_) => write!(f, ""),
            Self::Orphan => write!(f, ""), // U+2205 empty set
            Self::Diverged => write!(f, ""),
            Self::Ahead => write!(f, ""),
            Self::Behind => write!(f, ""),
        }
    }
}

impl MainState {
    /// Returns styled symbol with appropriate color, or None for None variant.
    ///
    /// Color semantics:
    /// - WARNING (yellow): WouldConflict - potential problem needing attention
    /// - HINT (dimmed): All others - informational states
    pub fn styled(&self) -> Option<String> {
        use color_print::cformat;
        match self {
            Self::None => None,
            Self::WouldConflict => Some(cformat!("<yellow>{self}</>")),
            _ => Some(cformat!("<dim>{self}</>")),
        }
    }

    /// Returns the integration reason if this is an integrated state, None otherwise.
    pub fn integration_reason(&self) -> Option<IntegrationReason> {
        match self {
            Self::Integrated(reason) => Some(*reason),
            _ => None,
        }
    }

    /// Returns the JSON string representation for main_state field.
    pub fn as_json_str(self) -> Option<&'static str> {
        let s: &'static str = self.into();
        if s.is_empty() { None } else { Some(s) }
    }

    /// Compute from divergence counts, integration state, and same-commit-dirty flag.
    ///
    /// Priority: IsMain > Orphan > WouldConflict > integration > SameCommit > Diverged > Ahead > Behind
    ///
    /// Orphan takes priority over WouldConflict because:
    /// - Orphan is a fundamental property (no common ancestor)
    /// - Merge conflicts for orphan branches are expected but not actionable normally
    /// - Users should understand "this is an orphan branch" rather than "this would conflict"
    pub fn from_integration_and_counts(
        is_main: bool,
        would_conflict: bool,
        integration: Option<MainState>,
        is_same_commit_dirty: bool,
        is_orphan: bool,
        ahead: usize,
        behind: usize,
    ) -> Self {
        if is_main {
            Self::IsMain
        } else if is_orphan {
            Self::Orphan
        } else if would_conflict {
            Self::WouldConflict
        } else if let Some(state) = integration {
            state
        } else if is_same_commit_dirty {
            Self::SameCommit
        } else {
            match (ahead, behind) {
                (0, 0) => Self::None,
                (_, 0) => Self::Ahead,
                (0, _) => Self::Behind,
                _ => Self::Diverged,
            }
        }
    }
}

impl serde::Serialize for MainState {
    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
    where
        S: serde::Serializer,
    {
        serializer.serialize_str(&self.to_string())
    }
}

/// Worktree operation state
///
/// Represents blocking git operations in progress that require resolution.
/// These take priority over all other states in the Worktree column.
///
/// Priority: Conflicts (✘) > Rebase (⤴) > Merge (⤵)
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default, strum::IntoStaticStr)]
#[strum(serialize_all = "snake_case")]
pub enum OperationState {
    /// No operation in progress
    #[default]
    #[strum(serialize = "")]
    None,
    /// Actual merge conflicts (unmerged paths in working tree)
    Conflicts,
    /// Rebase in progress
    Rebase,
    /// Merge in progress
    Merge,
}

impl std::fmt::Display for OperationState {
    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
        match self {
            Self::None => Ok(()),
            Self::Conflicts => write!(f, ""),
            Self::Rebase => write!(f, ""),
            Self::Merge => write!(f, ""),
        }
    }
}

impl OperationState {
    /// Returns styled symbol with appropriate color, or None for None variant.
    ///
    /// Color semantics:
    /// - ERROR (red): Conflicts - blocking problems
    /// - WARNING (yellow): Rebase, Merge - active/stuck states
    pub fn styled(&self) -> Option<String> {
        use color_print::cformat;
        match self {
            Self::None => None,
            Self::Conflicts => Some(cformat!("<red>{self}</>")),
            Self::Rebase | Self::Merge => Some(cformat!("<yellow>{self}</>")),
        }
    }

    /// Returns the JSON string representation.
    pub fn as_json_str(self) -> Option<&'static str> {
        let s: &'static str = self.into();
        if s.is_empty() { None } else { Some(s) }
    }
}

impl serde::Serialize for OperationState {
    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
    where
        S: serde::Serializer,
    {
        serializer.serialize_str(&self.to_string())
    }
}

/// Active git operation in a worktree
///
/// Represents raw data about whether a worktree is in the middle of a git operation.
/// This is distinct from [`OperationState`] which is the display enum (includes Conflicts,
/// has symbols/colors).
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default, serde::Serialize, strum::IntoStaticStr)]
#[serde(rename_all = "kebab-case")]
#[strum(serialize_all = "kebab-case")]
pub enum ActiveGitOperation {
    #[strum(serialize = "")]
    #[serde(rename = "")]
    #[default]
    None,
    /// Rebase in progress (rebase-merge or rebase-apply directory exists)
    Rebase,
    /// Merge in progress (MERGE_HEAD exists)
    Merge,
}

impl ActiveGitOperation {
    pub fn is_none(&self) -> bool {
        matches!(self, Self::None)
    }
}

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

    // ============================================================================
    // Divergence Tests
    // ============================================================================

    #[test]
    fn test_divergence_from_counts_with_remote() {
        assert_eq!(
            Divergence::from_counts_with_remote(0, 0),
            Divergence::InSync
        );
        assert_eq!(Divergence::from_counts_with_remote(5, 0), Divergence::Ahead);
        assert_eq!(
            Divergence::from_counts_with_remote(0, 3),
            Divergence::Behind
        );
        assert_eq!(
            Divergence::from_counts_with_remote(5, 3),
            Divergence::Diverged
        );
    }

    #[test]
    fn test_divergence_symbol() {
        assert_eq!(Divergence::None.symbol(), "");
        assert_eq!(Divergence::InSync.symbol(), "|");
        assert_eq!(Divergence::Ahead.symbol(), "");
        assert_eq!(Divergence::Behind.symbol(), "");
        assert_eq!(Divergence::Diverged.symbol(), "");
    }

    #[test]
    fn test_divergence_styled() {
        use insta::assert_snapshot;
        assert!(Divergence::None.styled().is_none());
        assert_snapshot!(Divergence::InSync.styled().unwrap(), @"|");
        assert_snapshot!(Divergence::Ahead.styled().unwrap(), @"⇡");
        assert_snapshot!(Divergence::Behind.styled().unwrap(), @"⇣");
        assert_snapshot!(Divergence::Diverged.styled().unwrap(), @"⇅");
    }

    // ============================================================================
    // WorktreeState Tests
    // ============================================================================

    #[test]
    fn test_worktree_state_display() {
        assert_eq!(format!("{}", WorktreeState::None), "");
        assert_eq!(format!("{}", WorktreeState::BranchWorktreeMismatch), "");
        assert_eq!(format!("{}", WorktreeState::Prunable), "");
        assert_eq!(format!("{}", WorktreeState::Locked), "");
        assert_eq!(format!("{}", WorktreeState::Branch), "/");
    }

    #[test]
    fn test_worktree_state_serialize() {
        // Serialize to JSON and check the string representation
        let json = serde_json::to_string(&WorktreeState::None).unwrap();
        assert_eq!(json, "\"\"");

        let json = serde_json::to_string(&WorktreeState::BranchWorktreeMismatch).unwrap();
        assert_eq!(json, "\"\"");

        let json = serde_json::to_string(&WorktreeState::Branch).unwrap();
        assert_eq!(json, "\"/\"");
    }

    // ============================================================================
    // MainState Tests
    // ============================================================================

    #[test]
    fn test_main_state_display() {
        assert_eq!(format!("{}", MainState::None), "");
        assert_eq!(format!("{}", MainState::IsMain), "^");
        assert_eq!(format!("{}", MainState::WouldConflict), "");
        assert_eq!(format!("{}", MainState::Empty), "_");
        assert_eq!(format!("{}", MainState::SameCommit), ""); // en-dash
        assert_eq!(
            format!("{}", MainState::Integrated(IntegrationReason::Ancestor)),
            ""
        );
        assert_eq!(format!("{}", MainState::Orphan), ""); // empty set
        assert_eq!(format!("{}", MainState::Diverged), "");
        assert_eq!(format!("{}", MainState::Ahead), "");
        assert_eq!(format!("{}", MainState::Behind), "");
    }

    #[test]
    fn test_main_state_styled() {
        use insta::assert_snapshot;
        assert!(MainState::None.styled().is_none());
        assert_snapshot!(MainState::WouldConflict.styled().unwrap(), @"✗");
        assert_snapshot!(MainState::IsMain.styled().unwrap(), @"^");
        assert_snapshot!(MainState::Ahead.styled().unwrap(), @"↑");
        assert_snapshot!(MainState::Orphan.styled().unwrap(), @"∅");
    }

    #[test]
    fn test_main_state_serialize() {
        let json = serde_json::to_string(&MainState::None).unwrap();
        assert_eq!(json, "\"\"");

        let json = serde_json::to_string(&MainState::IsMain).unwrap();
        assert_eq!(json, "\"^\"");

        let json = serde_json::to_string(&MainState::Diverged).unwrap();
        assert_eq!(json, "\"\"");

        let json = serde_json::to_string(&MainState::Orphan).unwrap();
        assert_eq!(json, "\"\"");
    }

    #[test]
    fn test_main_state_as_json_str() {
        assert_eq!(MainState::None.as_json_str(), None);
        assert_eq!(MainState::IsMain.as_json_str(), Some("is_main"));
        assert_eq!(
            MainState::WouldConflict.as_json_str(),
            Some("would_conflict")
        );
        assert_eq!(MainState::Empty.as_json_str(), Some("empty"));
        assert_eq!(MainState::SameCommit.as_json_str(), Some("same_commit"));
        assert_eq!(
            MainState::Integrated(IntegrationReason::TreesMatch).as_json_str(),
            Some("integrated")
        );
        assert_eq!(MainState::Diverged.as_json_str(), Some("diverged"));
        assert_eq!(MainState::Ahead.as_json_str(), Some("ahead"));
        assert_eq!(MainState::Behind.as_json_str(), Some("behind"));
    }

    #[test]
    fn test_integration_reason_into_static_str() {
        let s: &'static str = IntegrationReason::SameCommit.into();
        assert_eq!(s, "same-commit");
        let s: &'static str = IntegrationReason::Ancestor.into();
        assert_eq!(s, "ancestor");
        let s: &'static str = IntegrationReason::TreesMatch.into();
        assert_eq!(s, "trees-match");
        let s: &'static str = IntegrationReason::NoAddedChanges.into();
        assert_eq!(s, "no-added-changes");
        let s: &'static str = IntegrationReason::MergeAddsNothing.into();
        assert_eq!(s, "merge-adds-nothing");
        let s: &'static str = IntegrationReason::PatchIdMatch.into();
        assert_eq!(s, "patch-id-match");
    }

    #[test]
    fn test_main_state_integration_reason() {
        // Non-integrated states return None
        assert_eq!(MainState::None.integration_reason(), None);
        assert_eq!(MainState::IsMain.integration_reason(), None);
        assert_eq!(MainState::WouldConflict.integration_reason(), None);
        assert_eq!(MainState::Empty.integration_reason(), None);
        assert_eq!(MainState::SameCommit.integration_reason(), None);
        assert_eq!(MainState::Diverged.integration_reason(), None);
        assert_eq!(MainState::Ahead.integration_reason(), None);
        assert_eq!(MainState::Behind.integration_reason(), None);

        // Integrated states return the reason
        assert_eq!(
            MainState::Integrated(IntegrationReason::Ancestor).integration_reason(),
            Some(IntegrationReason::Ancestor)
        );
        assert_eq!(
            MainState::Integrated(IntegrationReason::TreesMatch).integration_reason(),
            Some(IntegrationReason::TreesMatch)
        );
        assert_eq!(
            MainState::Integrated(IntegrationReason::NoAddedChanges).integration_reason(),
            Some(IntegrationReason::NoAddedChanges)
        );
        assert_eq!(
            MainState::Integrated(IntegrationReason::MergeAddsNothing).integration_reason(),
            Some(IntegrationReason::MergeAddsNothing)
        );
        assert_eq!(
            MainState::Integrated(IntegrationReason::PatchIdMatch).integration_reason(),
            Some(IntegrationReason::PatchIdMatch)
        );
    }

    #[test]
    fn test_main_state_from_integration_and_counts() {
        // IsMain takes priority
        assert!(matches!(
            MainState::from_integration_and_counts(true, false, None, false, false, 5, 3),
            MainState::IsMain
        ));

        // Orphan takes priority over WouldConflict (orphan is root cause)
        assert!(matches!(
            MainState::from_integration_and_counts(false, true, None, false, true, 0, 0),
            MainState::Orphan
        ));

        // WouldConflict when not orphan
        assert!(matches!(
            MainState::from_integration_and_counts(false, true, None, false, false, 5, 3),
            MainState::WouldConflict
        ));

        // Empty (passed as integration state - same commit with clean working tree)
        assert!(matches!(
            MainState::from_integration_and_counts(
                false,
                false,
                Some(MainState::Empty),
                false,
                false,
                0,
                0
            ),
            MainState::Empty
        ));

        // Integrated (passed as integration state)
        assert!(matches!(
            MainState::from_integration_and_counts(
                false,
                false,
                Some(MainState::Integrated(IntegrationReason::Ancestor)),
                false,
                false,
                0,
                5
            ),
            MainState::Integrated(IntegrationReason::Ancestor)
        ));

        // SameCommit (via is_same_commit_dirty flag, NOT integration)
        assert!(matches!(
            MainState::from_integration_and_counts(false, false, None, true, false, 0, 0),
            MainState::SameCommit
        ));

        // Orphan (no common ancestor with default branch)
        assert!(matches!(
            MainState::from_integration_and_counts(false, false, None, false, true, 0, 0),
            MainState::Orphan
        ));

        // Diverged (both ahead and behind)
        assert!(matches!(
            MainState::from_integration_and_counts(false, false, None, false, false, 3, 2),
            MainState::Diverged
        ));

        // Ahead only
        assert!(matches!(
            MainState::from_integration_and_counts(false, false, None, false, false, 3, 0),
            MainState::Ahead
        ));

        // Behind only
        assert!(matches!(
            MainState::from_integration_and_counts(false, false, None, false, false, 0, 2),
            MainState::Behind
        ));

        // None (in sync)
        assert!(matches!(
            MainState::from_integration_and_counts(false, false, None, false, false, 0, 0),
            MainState::None
        ));
    }

    // ============================================================================
    // OperationState Tests
    // ============================================================================

    #[test]
    fn test_operation_state_display() {
        assert_eq!(format!("{}", OperationState::None), "");
        assert_eq!(format!("{}", OperationState::Conflicts), "");
        assert_eq!(format!("{}", OperationState::Rebase), "");
        assert_eq!(format!("{}", OperationState::Merge), "");
    }

    #[test]
    fn test_operation_state_styled() {
        use insta::assert_snapshot;
        assert!(OperationState::None.styled().is_none());
        assert_snapshot!(OperationState::Conflicts.styled().unwrap(), @"✘");
        assert_snapshot!(OperationState::Rebase.styled().unwrap(), @"⤴");
        assert_snapshot!(OperationState::Merge.styled().unwrap(), @"⤵");
    }

    #[test]
    fn test_operation_state_serialize() {
        let json = serde_json::to_string(&OperationState::None).unwrap();
        assert_eq!(json, "\"\"");

        let json = serde_json::to_string(&OperationState::Conflicts).unwrap();
        assert_eq!(json, "\"\"");
    }

    #[test]
    fn test_operation_state_as_json_str() {
        assert_eq!(OperationState::None.as_json_str(), None);
        assert_eq!(OperationState::Conflicts.as_json_str(), Some("conflicts"));
        assert_eq!(OperationState::Rebase.as_json_str(), Some("rebase"));
        assert_eq!(OperationState::Merge.as_json_str(), Some("merge"));
    }

    // ============================================================================
    // ActiveGitOperation Tests
    // ============================================================================

    #[test]
    fn test_git_operation_state_is_none() {
        assert!(ActiveGitOperation::None.is_none());
        assert!(ActiveGitOperation::default().is_none());
        assert!(!ActiveGitOperation::Rebase.is_none());
        assert!(!ActiveGitOperation::Merge.is_none());
    }
}