On Fri, Nov 21, 2025 at 12:02 PM Ajith Ramanathan <[email protected]> wrote:
>
> I'm trying to execute
>
> git -c gc.reflogexpire=0 -c gc.reflogexpireunreachable=0 -c 
> gc.rerereresolved=0 -c gc.rerereunresolved=0 -c gc.prunreexpire=now gc
>
> from inside git.  When I run this in a terminal I get output like:
>
> Enumerating objects: 539, done.
> Counting objects: 100% (539/539), done.
> Delta compression using up to 4 threads
> Compressing objects: 100% (235/235), done.
> Writing objects: 100% (539/539), done.
> Total 539 (delta 298), reused 539 (delta 298), pack-reused 0 (from 0)
> Enumerating cruft objects: 491, done.
> Traversing cruft objects: 597, done.
> Counting objects: 100% (501/501), done.
> Delta compression using up to 4 threads
> Compressing objects: 100% (216/216), done.
> Writing objects: 100% (501/501), done.
> Total 501 (delta 284), reused 501 (delta 284), pack-reused 0 (from 0)
>
> However, when I run it using os/exec.Command I get nothing on stderr or 
> stdout.  Other git commands do output to stderr and stdout, so I'm a little 
> mystified.  Here is a test program demonstrating this:
>
> package main
>
> import (
> "fmt"
> "io"
> "os/exec"
> )
>
> func run(cmd string, args ...string) {
> runner := exec.Command(cmd, args...)
>
> outp, _ := runner.StdoutPipe()
> errp, _ := runner.StderrPipe()
>
> if err := runner.Start(); err != nil {
> panic(err)
> }
>
> outs, _ := io.ReadAll(outp)
> errs, _ := io.ReadAll(errp)
>
> err := runner.Wait()
>
> fmt.Printf("cmd: %q\n", runner.String())
> fmt.Printf("stdout: %q\n", outs)
> fmt.Printf("stderr: %q\n", errs)
> fmt.Printf("err: %v\n", err)
> }
>
> func main() {
> run("git", "--version")
> fmt.Println("-----------------------------------------------------------------------------")
> run(
> "git",
> "-c", "gc.reflogexpire=0",
> "-c", "gc.reflogexpireunreachable=0",
> "-c", "gc.rerereresolved=0",
> "-c", "gc.rerereunresolved=0",
> "-c", "gc.prunreexpire=now",
> "gc",
> )
> fmt.Println("-----------------------------------------------------------------------------")
> run("git", "skidoosh")
> }
>
> and here is its output:
>
> cmd: "/usr/bin/git --version"
> stdout: "git version 2.51.2\n"
> stderr: ""
> err: <nil>
> -----------------------------------------------------------------------------
> cmd: "/usr/bin/git -c gc.reflogexpire=0 -c gc.reflogexpireunreachable=0 -c 
> gc.rerereresolved=0 -c gc.rerereunresolved=0 -c gc.prunreexpire=now gc"
> stdout: ""
> stderr: ""
> err: <nil>
> -----------------------------------------------------------------------------
> cmd: "/usr/bin/git skidoosh"
> stdout: ""
> stderr: "git: 'skidoosh' is not a git command. See 'git --help'.\n"
> err: exit status 1
>
> I feel like I'm missing something obvious, but it isn't clear what that might 
> me.

"git gc" changes its output based on whether it is connected to a tty.

You'll see the same effect if you run "git gc >/tmp/stdout 2>/tmp/stderr".

I don't know why "git gc" behaves that way.

Ian

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion visit 
https://groups.google.com/d/msgid/golang-nuts/CAOyqgcVZjr_bVu9qQvExqEX%2BWHXzQvevUGJQEyQCSRXqQ-r1kw%40mail.gmail.com.

Reply via email to