github.com/AlpineAIO/wails/v2@v2.0.0-beta.32.0.20240505041856-1047a8fa5fef/pkg/git/git.go (about)

     1  package git
     2  
     3  import (
     4  	"html/template"
     5  	"runtime"
     6  	"strings"
     7  
     8  	"github.com/AlpineAIO/wails/v2/internal/shell"
     9  )
    10  
    11  func gitcommand() string {
    12  	gitcommand := "git"
    13  	if runtime.GOOS == "windows" {
    14  		gitcommand = "git.exe"
    15  	}
    16  
    17  	return gitcommand
    18  }
    19  
    20  // IsInstalled returns true if git is installed for the given platform
    21  func IsInstalled() bool {
    22  	return shell.CommandExists(gitcommand())
    23  }
    24  
    25  // Email tries to retrieve the
    26  func Email() (string, error) {
    27  	stdout, _, err := shell.RunCommand(".", gitcommand(), "config", "user.email")
    28  	return stdout, err
    29  }
    30  
    31  // Name tries to retrieve the
    32  func Name() (string, error) {
    33  	stdout, _, err := shell.RunCommand(".", gitcommand(), "config", "user.name")
    34  	name := template.JSEscapeString(strings.TrimSpace(stdout))
    35  	return name, err
    36  }
    37  
    38  func InitRepo(projectDir string) error {
    39  	_, _, err := shell.RunCommand(projectDir, gitcommand(), "init")
    40  	return err
    41  }