github.com/git-lfs/git-lfs@v2.5.2+incompatible/subprocess/pty_nix.go (about)

     1  // +build !windows
     2  
     3  package subprocess
     4  
     5  import (
     6  	"os/exec"
     7  	"syscall"
     8  
     9  	"github.com/kr/pty"
    10  )
    11  
    12  // NewTty creates a pseudo-TTY for a command and modifies it appropriately so
    13  // the command thinks it's a real terminal
    14  func NewTty(cmd *exec.Cmd) *Tty {
    15  	tty := &Tty{}
    16  	tty.cmd = cmd
    17  	// Assign pty/tty so git thinks it's a real terminal
    18  	tty.outpty, tty.outtty, _ = pty.Open()
    19  	cmd.Stdin = tty.outtty
    20  	cmd.Stdout = tty.outtty
    21  	tty.errpty, tty.errtty, _ = pty.Open()
    22  	cmd.Stderr = tty.errtty
    23  	if cmd.SysProcAttr == nil {
    24  		cmd.SysProcAttr = &syscall.SysProcAttr{}
    25  	}
    26  	cmd.SysProcAttr.Setctty = true
    27  	cmd.SysProcAttr.Setsid = true
    28  
    29  	return tty
    30  }