bashkit 0.1.14

Virtual bash interpreter for multi-tenant environments
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
//! Git builtin command.
//!
//! Provides virtual git operations on the virtual filesystem.
//!
//! # Supported Subcommands (Phase 1)
//!
//! - `git init [path]` - Create empty repository
//! - `git config [--global] <key> [value]` - Get/set config
//! - `git add <pathspec>...` - Stage files
//! - `git commit -m <message>` - Record changes
//! - `git status` - Show working tree status
//! - `git log [-n N]` - Show commit history
//!
//! # Security
//!
//! All operations are confined to the virtual filesystem and use
//! the configured author identity. See `specs/006-threat-model.md`
//! Section 9: Git Security (TM-GIT-*).
//!
//! # Example
//!
//! ```bash
//! git init /myrepo
//! cd /myrepo
//! echo "Hello" > README.md
//! git add README.md
//! git commit -m "Initial commit"
//! git log
//! ```

use async_trait::async_trait;

use super::{Context, resolve_path};
use crate::error::Result;
use crate::interpreter::ExecResult;

/// Git builtin command.
pub struct Git;

/// Convert a git client error into a standard git error result (exit code 128).
fn git_err(e: impl std::fmt::Display) -> Result<ExecResult> {
    Ok(ExecResult::err(format!("{}\n", e), 128))
}

#[async_trait]
impl super::Builtin for Git {
    async fn execute(&self, ctx: Context<'_>) -> Result<ExecResult> {
        // Check if git client is available
        #[cfg(feature = "git")]
        {
            if let Some(git_client) = ctx.git_client {
                return execute_git(ctx, git_client).await;
            }
        }

        // Git not configured
        Ok(ExecResult::err(
            "git: not configured\n\
             Note: Git operations require the 'git' feature and configuration via Bash::builder().git()\n"
                .to_string(),
            1,
        ))
    }
}

#[cfg(feature = "git")]
async fn execute_git(ctx: Context<'_>, git_client: &crate::git::GitClient) -> Result<ExecResult> {
    if ctx.args.is_empty() {
        return Ok(ExecResult::err(
            "usage: git <command> [<args>]\n\n\
             Available commands:\n\
             \tinit      Create an empty Git repository\n\
             \tconfig    Get and set repository options\n\
             \tadd       Add file contents to the index\n\
             \tcommit    Record changes to the repository\n\
             \tstatus    Show the working tree status\n\
             \tlog       Show commit logs\n\
             \tbranch    List, create, or delete branches\n\
             \tcheckout  Switch branches or restore files\n\
             \tdiff      Show changes (simplified)\n\
             \treset     Reset current HEAD\n\
             \tremote    Manage remotes\n\
             \tclone     Clone a repository (URL validation only)\n\
             \tfetch     Fetch from remote (URL validation only)\n\
             \tpush      Push to remote (URL validation only)\n\
             \tpull      Pull from remote (URL validation only)\n\
             \tshow      Show commit or file content\n\
             \tls-files  List tracked files\n\
             \trev-parse Resolve refs and repo metadata\n\
             \trestore   Restore working tree or index files\n\
             \tmerge-base Find merge base between commits\n\
             \tgrep      Search tracked file contents\n"
                .to_string(),
            1,
        ));
    }

    let subcommand = &ctx.args[0];
    let subargs = &ctx.args[1..];

    match subcommand.as_str() {
        "init" => git_init(ctx, git_client, subargs).await,
        "config" => git_config(ctx, git_client, subargs).await,
        "add" => git_add(ctx, git_client, subargs).await,
        "commit" => git_commit(ctx, git_client, subargs).await,
        "status" => git_status(ctx, git_client).await,
        "log" => git_log(ctx, git_client, subargs).await,
        "remote" => git_remote(ctx, git_client, subargs).await,
        "clone" => git_clone(ctx, git_client, subargs).await,
        "fetch" => git_fetch(ctx, git_client, subargs).await,
        "push" => git_push(ctx, git_client, subargs).await,
        "pull" => git_pull(ctx, git_client, subargs).await,
        "branch" => git_branch(ctx, git_client, subargs).await,
        "checkout" => git_checkout(ctx, git_client, subargs).await,
        "diff" => git_diff(ctx, git_client, subargs).await,
        "reset" => git_reset(ctx, git_client, subargs).await,
        "show" => git_show(ctx, git_client, subargs).await,
        "ls-files" => git_ls_files(ctx, git_client).await,
        "rev-parse" => git_rev_parse(ctx, git_client, subargs).await,
        "restore" => git_restore(ctx, git_client, subargs).await,
        "merge-base" => git_merge_base(ctx, git_client, subargs).await,
        "grep" => git_grep(ctx, git_client, subargs).await,
        _ => Ok(ExecResult::err(
            format!(
                "git: '{}' is not a git command. See 'git --help'.\n",
                subcommand
            ),
            1,
        )),
    }
}

#[cfg(feature = "git")]
async fn git_init(
    ctx: Context<'_>,
    git_client: &crate::git::GitClient,
    args: &[String],
) -> Result<ExecResult> {
    // Parse path argument (default to cwd)
    let path = if args.is_empty() {
        ctx.cwd.clone()
    } else {
        resolve_path(ctx.cwd, &args[0])
    };

    // Create directory if it doesn't exist
    if !ctx.fs.exists(&path).await? {
        ctx.fs.mkdir(&path, true).await?;
    }

    match git_client.init(&ctx.fs, &path).await {
        Ok(output) => Ok(ExecResult::ok(output)),
        Err(e) => git_err(e),
    }
}

#[cfg(feature = "git")]
async fn git_config(
    ctx: Context<'_>,
    git_client: &crate::git::GitClient,
    args: &[String],
) -> Result<ExecResult> {
    // Parse arguments
    let mut key: Option<&str> = None;
    let mut value: Option<&str> = None;
    let mut _global = false;

    let mut i = 0;
    while i < args.len() {
        let arg = &args[i];
        if arg == "--global" || arg == "--system" {
            // Ignore --global/--system flags (we only support repo config)
            _global = true;
        } else if key.is_none() {
            key = Some(arg);
        } else if value.is_none() {
            value = Some(arg);
        }
        i += 1;
    }

    let Some(key) = key else {
        return Ok(ExecResult::err(
            "usage: git config [<options>] <name> [<value>]\n".to_string(),
            129,
        ));
    };

    // Get or set based on whether value is provided
    match value {
        Some(value) => {
            // Set config
            match git_client.config_set(&ctx.fs, ctx.cwd, key, value).await {
                Ok(()) => Ok(ExecResult::ok(String::new())),
                Err(e) => git_err(e),
            }
        }
        None => {
            // Get config
            match git_client.config_get(&ctx.fs, ctx.cwd, key).await {
                Ok(Some(value)) => Ok(ExecResult::ok(format!("{}\n", value))),
                Ok(None) => Ok(ExecResult::ok(String::new())),
                Err(e) => git_err(e),
            }
        }
    }
}

#[cfg(feature = "git")]
async fn git_add(
    ctx: Context<'_>,
    git_client: &crate::git::GitClient,
    args: &[String],
) -> Result<ExecResult> {
    if args.is_empty() {
        return Ok(ExecResult::err(
            "Nothing specified, nothing added.\n\
             hint: Maybe you wanted to say 'git add .'?\n"
                .to_string(),
            0,
        ));
    }

    let paths: Vec<&str> = args.iter().map(|s| s.as_str()).collect();

    match git_client.add(&ctx.fs, ctx.cwd, &paths).await {
        Ok(()) => Ok(ExecResult::ok(String::new())),
        Err(e) => git_err(e),
    }
}

#[cfg(feature = "git")]
async fn git_commit(
    ctx: Context<'_>,
    git_client: &crate::git::GitClient,
    args: &[String],
) -> Result<ExecResult> {
    // Parse -m <message>
    let mut message: Option<String> = None;

    let mut i = 0;
    while i < args.len() {
        let arg = &args[i];
        if arg == "-m" {
            if i + 1 < args.len() {
                message = Some(args[i + 1].clone());
                i += 1;
            }
        } else if let Some(msg) = arg.strip_prefix("-m") {
            message = Some(msg.to_string());
        }
        i += 1;
    }

    let Some(message) = message else {
        return Ok(ExecResult::err(
            "error: switch 'm' requires a value\n".to_string(),
            128,
        ));
    };

    match git_client.commit(&ctx.fs, ctx.cwd, &message).await {
        Ok(output) => Ok(ExecResult::ok(output)),
        Err(e) => Ok(ExecResult::err(format!("{}\n", e), 1)),
    }
}

#[cfg(feature = "git")]
async fn git_status(ctx: Context<'_>, git_client: &crate::git::GitClient) -> Result<ExecResult> {
    match git_client.status(&ctx.fs, ctx.cwd).await {
        Ok(status) => {
            let output = git_client.format_status(&status);
            Ok(ExecResult::ok(output))
        }
        Err(e) => git_err(e),
    }
}

#[cfg(feature = "git")]
async fn git_log(
    ctx: Context<'_>,
    git_client: &crate::git::GitClient,
    args: &[String],
) -> Result<ExecResult> {
    // Parse -n <number> or -<number>
    let mut limit: Option<usize> = None;

    let mut i = 0;
    while i < args.len() {
        let arg = &args[i];
        if arg == "-n" {
            if i + 1 < args.len() {
                limit = args[i + 1].parse().ok();
                i += 1;
            }
        } else if let Some(n) = arg.strip_prefix("-n") {
            limit = n.parse().ok();
        } else if arg.starts_with('-') && arg[1..].parse::<usize>().is_ok() {
            limit = arg[1..].parse().ok();
        }
        i += 1;
    }

    match git_client.log(&ctx.fs, ctx.cwd, limit).await {
        Ok(entries) => {
            if entries.is_empty() {
                // No commits yet
                return Ok(ExecResult::err(
                    "fatal: your current branch 'master' does not have any commits yet\n"
                        .to_string(),
                    128,
                ));
            }
            let output = git_client.format_log(&entries);
            Ok(ExecResult::ok(output))
        }
        Err(e) => git_err(e),
    }
}

#[cfg(feature = "git")]
async fn git_remote(
    ctx: Context<'_>,
    git_client: &crate::git::GitClient,
    args: &[String],
) -> Result<ExecResult> {
    if args.is_empty() {
        // List remotes (names only)
        match git_client.remote_list(&ctx.fs, ctx.cwd).await {
            Ok(remotes) => {
                let output: String = remotes.iter().map(|r| format!("{}\n", r.name)).collect();
                Ok(ExecResult::ok(output))
            }
            Err(e) => git_err(e),
        }
    } else {
        let subcmd = &args[0];
        let subargs = &args[1..];

        match subcmd.as_str() {
            "-v" | "--verbose" => {
                // List remotes with URLs
                match git_client.remote_list(&ctx.fs, ctx.cwd).await {
                    Ok(remotes) => {
                        let output: String = remotes
                            .iter()
                            .flat_map(|r| {
                                vec![
                                    format!("{}\t{} (fetch)\n", r.name, r.url),
                                    format!("{}\t{} (push)\n", r.name, r.url),
                                ]
                            })
                            .collect();
                        Ok(ExecResult::ok(output))
                    }
                    Err(e) => git_err(e),
                }
            }
            "add" => {
                if subargs.len() < 2 {
                    return Ok(ExecResult::err(
                        "usage: git remote add <name> <url>\n".to_string(),
                        129,
                    ));
                }
                let name = &subargs[0];
                let url = &subargs[1];
                match git_client.remote_add(&ctx.fs, ctx.cwd, name, url).await {
                    Ok(()) => Ok(ExecResult::ok(String::new())),
                    Err(e) => git_err(e),
                }
            }
            "remove" | "rm" => {
                if subargs.is_empty() {
                    return Ok(ExecResult::err(
                        "usage: git remote remove <name>\n".to_string(),
                        129,
                    ));
                }
                let name = &subargs[0];
                match git_client.remote_remove(&ctx.fs, ctx.cwd, name).await {
                    Ok(()) => Ok(ExecResult::ok(String::new())),
                    Err(e) => git_err(e),
                }
            }
            _ => Ok(ExecResult::err(
                format!(
                    "error: Unknown subcommand: {}\n\
                     usage: git remote [-v | --verbose]\n\
                            git remote add <name> <url>\n\
                            git remote remove <name>\n",
                    subcmd
                ),
                1,
            )),
        }
    }
}

#[cfg(feature = "git")]
async fn git_clone(
    ctx: Context<'_>,
    git_client: &crate::git::GitClient,
    args: &[String],
) -> Result<ExecResult> {
    if args.is_empty() {
        return Ok(ExecResult::err(
            "usage: git clone <repository> [<directory>]\n".to_string(),
            129,
        ));
    }

    let url = &args[0];
    let dest = if args.len() > 1 {
        resolve_path(ctx.cwd, &args[1])
    } else {
        // Extract repo name from URL
        let name = url
            .rsplit('/')
            .next()
            .unwrap_or("repo")
            .trim_end_matches(".git");
        resolve_path(ctx.cwd, name)
    };

    match git_client.clone(&ctx.fs, url, &dest).await {
        Ok(output) => Ok(ExecResult::ok(output)),
        Err(e) => git_err(e),
    }
}

#[cfg(feature = "git")]
async fn git_fetch(
    ctx: Context<'_>,
    git_client: &crate::git::GitClient,
    args: &[String],
) -> Result<ExecResult> {
    let remote = if args.is_empty() { "origin" } else { &args[0] };

    match git_client.fetch(&ctx.fs, ctx.cwd, remote).await {
        Ok(output) => Ok(ExecResult::ok(output)),
        Err(e) => git_err(e),
    }
}

#[cfg(feature = "git")]
async fn git_push(
    ctx: Context<'_>,
    git_client: &crate::git::GitClient,
    args: &[String],
) -> Result<ExecResult> {
    let remote = if args.is_empty() { "origin" } else { &args[0] };

    match git_client.push(&ctx.fs, ctx.cwd, remote).await {
        Ok(output) => Ok(ExecResult::ok(output)),
        Err(e) => git_err(e),
    }
}

#[cfg(feature = "git")]
async fn git_pull(
    ctx: Context<'_>,
    git_client: &crate::git::GitClient,
    args: &[String],
) -> Result<ExecResult> {
    let remote = if args.is_empty() { "origin" } else { &args[0] };

    match git_client.pull(&ctx.fs, ctx.cwd, remote).await {
        Ok(output) => Ok(ExecResult::ok(output)),
        Err(e) => git_err(e),
    }
}

#[cfg(feature = "git")]
async fn git_branch(
    ctx: Context<'_>,
    git_client: &crate::git::GitClient,
    args: &[String],
) -> Result<ExecResult> {
    if args.is_empty() {
        // List branches
        match git_client.branch_list(&ctx.fs, ctx.cwd).await {
            Ok(branches) => {
                let output = git_client.format_branch_list(&branches);
                Ok(ExecResult::ok(output))
            }
            Err(e) => git_err(e),
        }
    } else if args[0] == "-d" || args[0] == "-D" {
        // Delete branch
        if args.len() < 2 {
            return Ok(ExecResult::err(
                "error: branch name required\n".to_string(),
                129,
            ));
        }
        match git_client.branch_delete(&ctx.fs, ctx.cwd, &args[1]).await {
            Ok(()) => Ok(ExecResult::ok(format!("Deleted branch {}.\n", args[1]))),
            Err(e) => Ok(ExecResult::err(format!("{}\n", e), 1)),
        }
    } else {
        // Create branch
        match git_client.branch_create(&ctx.fs, ctx.cwd, &args[0]).await {
            Ok(()) => Ok(ExecResult::ok(String::new())),
            Err(e) => git_err(e),
        }
    }
}

#[cfg(feature = "git")]
async fn git_checkout(
    ctx: Context<'_>,
    git_client: &crate::git::GitClient,
    args: &[String],
) -> Result<ExecResult> {
    if args.is_empty() {
        return Ok(ExecResult::err(
            "error: you must specify a branch or commit to checkout\n".to_string(),
            129,
        ));
    }

    // Handle -b flag for creating and checking out a new branch
    if args[0] == "-b" {
        if args.len() < 2 {
            return Ok(ExecResult::err(
                "error: switch 'b' requires a value\n".to_string(),
                129,
            ));
        }
        // Create branch first
        if let Err(e) = git_client.branch_create(&ctx.fs, ctx.cwd, &args[1]).await {
            return git_err(e);
        }
        // Then checkout
        match git_client.checkout(&ctx.fs, ctx.cwd, &args[1]).await {
            Ok(output) => Ok(ExecResult::ok(output)),
            Err(e) => Ok(ExecResult::err(format!("{}\n", e), 1)),
        }
    } else {
        match git_client.checkout(&ctx.fs, ctx.cwd, &args[0]).await {
            Ok(output) => Ok(ExecResult::ok(output)),
            Err(e) => Ok(ExecResult::err(format!("{}\n", e), 1)),
        }
    }
}

#[cfg(feature = "git")]
async fn git_diff(
    ctx: Context<'_>,
    git_client: &crate::git::GitClient,
    args: &[String],
) -> Result<ExecResult> {
    let from = args.first().map(|s| s.as_str());
    let to = args.get(1).map(|s| s.as_str());

    match git_client.diff(&ctx.fs, ctx.cwd, from, to).await {
        Ok(output) => Ok(ExecResult::ok(output)),
        Err(e) => git_err(e),
    }
}

#[cfg(feature = "git")]
async fn git_reset(
    ctx: Context<'_>,
    git_client: &crate::git::GitClient,
    args: &[String],
) -> Result<ExecResult> {
    // Parse mode and target
    let mut mode = "--mixed"; // default
    let mut target: Option<&str> = None;

    for arg in args {
        if arg.starts_with("--") {
            mode = arg.as_str();
        } else {
            target = Some(arg.as_str());
        }
    }

    match git_client.reset(&ctx.fs, ctx.cwd, mode, target).await {
        Ok(output) => Ok(ExecResult::ok(output)),
        Err(e) => git_err(e),
    }
}

#[cfg(feature = "git")]
async fn git_show(
    ctx: Context<'_>,
    git_client: &crate::git::GitClient,
    args: &[String],
) -> Result<ExecResult> {
    let target = args.first().map(|s| s.as_str());
    match git_client.show(&ctx.fs, ctx.cwd, target).await {
        Ok(output) => Ok(ExecResult::ok(output)),
        Err(e) => git_err(e),
    }
}

#[cfg(feature = "git")]
async fn git_ls_files(ctx: Context<'_>, git_client: &crate::git::GitClient) -> Result<ExecResult> {
    match git_client.ls_files(&ctx.fs, ctx.cwd).await {
        Ok(files) => {
            let output: String = files.iter().map(|f| format!("{}\n", f)).collect();
            Ok(ExecResult::ok(output))
        }
        Err(e) => git_err(e),
    }
}

#[cfg(feature = "git")]
async fn git_rev_parse(
    ctx: Context<'_>,
    git_client: &crate::git::GitClient,
    args: &[String],
) -> Result<ExecResult> {
    if args.is_empty() {
        return Ok(ExecResult::err(
            "usage: git rev-parse [<options>] [<args>...]\n".to_string(),
            129,
        ));
    }
    let refs: Vec<&str> = args.iter().map(|s| s.as_str()).collect();
    match git_client.rev_parse(&ctx.fs, ctx.cwd, &refs).await {
        Ok(output) => Ok(ExecResult::ok(output)),
        Err(e) => git_err(e),
    }
}

#[cfg(feature = "git")]
async fn git_restore(
    ctx: Context<'_>,
    git_client: &crate::git::GitClient,
    args: &[String],
) -> Result<ExecResult> {
    if args.is_empty() {
        return Ok(ExecResult::err(
            "usage: git restore [--staged] <pathspec>...\n".to_string(),
            129,
        ));
    }

    let staged = args.iter().any(|a| a == "--staged");
    let paths: Vec<&str> = args
        .iter()
        .filter(|a| !a.starts_with('-'))
        .map(|s| s.as_str())
        .collect();

    if paths.is_empty() {
        return Ok(ExecResult::err(
            "error: you must specify path(s) to restore\n".to_string(),
            128,
        ));
    }

    match git_client.restore(&ctx.fs, ctx.cwd, &paths, staged).await {
        Ok(output) => Ok(ExecResult::ok(output)),
        Err(e) => git_err(e),
    }
}

#[cfg(feature = "git")]
async fn git_merge_base(
    ctx: Context<'_>,
    git_client: &crate::git::GitClient,
    args: &[String],
) -> Result<ExecResult> {
    if args.len() < 2 {
        return Ok(ExecResult::err(
            "usage: git merge-base <commit> <commit>\n".to_string(),
            129,
        ));
    }
    match git_client
        .merge_base(&ctx.fs, ctx.cwd, &args[0], &args[1])
        .await
    {
        Ok(output) => Ok(ExecResult::ok(output)),
        Err(e) => Ok(ExecResult::err(format!("{}\n", e), 1)),
    }
}

#[cfg(feature = "git")]
async fn git_grep(
    ctx: Context<'_>,
    git_client: &crate::git::GitClient,
    args: &[String],
) -> Result<ExecResult> {
    if args.is_empty() {
        return Ok(ExecResult::err(
            "usage: git grep <pattern> [<pathspec>...]\n".to_string(),
            129,
        ));
    }

    let pattern = &args[0];
    let paths: Vec<&str> = args[1..].iter().map(|s| s.as_str()).collect();

    match git_client.grep(&ctx.fs, ctx.cwd, pattern, &paths).await {
        Ok(output) => {
            if output.is_empty() {
                Ok(ExecResult::with_code(String::new(), 1))
            } else {
                Ok(ExecResult::ok(output))
            }
        }
        Err(e) => git_err(e),
    }
}