func LsRemote(remote, remoteRef string) (string, error) { if remote == "" { return "", errors.New("remote required") } if remoteRef == "" { return subprocess.SimpleExec("git", "ls-remote", remote) } return subprocess.SimpleExec("git", "ls-remote", remote, remoteRef) }
// UnsetLocalKey removes the git config value for the key from the specified config file func (c *gitConfig) UnsetLocalKey(file, key string) { args := make([]string, 1, 5) args[0] = "config" if len(file) > 0 { args = append(args, "--file", file) } args = append(args, "--unset", key) subprocess.SimpleExec("git", args...) }
// SetLocal sets the git config value for the key in the specified config file func (c *gitConfig) SetLocal(file, key, val string) (string, error) { args := make([]string, 1, 5) args[0] = "config" if len(file) > 0 { args = append(args, "--file", file) } args = append(args, key, val) return subprocess.SimpleExec("git", args...) }
// Version returns the git version func (c *gitConfig) Version() (string, error) { c.mu.Lock() defer c.mu.Unlock() if len(c.gitVersion) == 0 { v, err := subprocess.SimpleExec("git", "version") if err != nil { return v, err } c.gitVersion = v } return c.gitVersion, nil }
func ResolveRef(ref string) (*Ref, error) { outp, err := subprocess.SimpleExec("git", "rev-parse", ref, "--symbolic-full-name", ref) if err != nil { return nil, err } lines := strings.Split(outp, "\n") if len(lines) <= 1 { return nil, fmt.Errorf("Git can't resolve ref: %q", ref) } fullref := &Ref{Sha: lines[0]} fullref.Type, fullref.Name = ParseRefToTypeAndName(lines[1]) return fullref, nil }
func ResolveRef(ref string) (*Ref, error) { outp, err := subprocess.SimpleExec("git", "rev-parse", ref, "--symbolic-full-name", ref) if err != nil { return nil, fmt.Errorf("Git can't resolve ref: %q", ref) } if outp == "" { return nil, fmt.Errorf("Git can't resolve ref: %q", ref) } lines := strings.Split(outp, "\n") fullref := &Ref{Sha: lines[0]} if len(lines) == 1 { // ref is a sha1 and has no symbolic-full-name fullref.Name = lines[0] // fullref.Sha fullref.Type = RefTypeOther return fullref, nil } // parse the symbolic-full-name fullref.Type, fullref.Name = ParseRefToTypeAndName(lines[1]) return fullref, nil }
// List lists all of the git config values func (c *gitConfig) List() (string, error) { return subprocess.SimpleExec("git", "config", "-l") }
func (c *gitConfig) UnsetGlobalSection(key string) { subprocess.SimpleExec("git", "config", "--global", "--remove-section", key) }
// UnsetGlobal removes the git config value for the key from the global config func (c *gitConfig) UnsetGlobal(key string) { subprocess.SimpleExec("git", "config", "--global", "--unset", key) }
// SetGlobal sets the git config value for the key in the global config func (c *gitConfig) SetGlobal(key, val string) { subprocess.SimpleExec("git", "config", "--global", key, val) }
// SetGlobal sets the git config value for the key in the global config func (c *gitConfig) SetGlobal(key, val string) (string, error) { return subprocess.SimpleExec("git", "config", "--global", key, val) }
// UnsetGlobalSection removes the entire named section from the system config func (c *gitConfig) UnsetSystemSection(key string) (string, error) { return subprocess.SimpleExec("git", "config", "--system", "--remove-section", key) }
// UnsetSystem removes the git config value for the key from the system config func (c *gitConfig) UnsetSystem(key string) (string, error) { return subprocess.SimpleExec("git", "config", "--system", "--unset", key) }
// UnsetGlobal removes the git config value for the key from the global config func (c *gitConfig) UnsetGlobal(key string) (string, error) { return subprocess.SimpleExec("git", "config", "--global", "--unset", key) }
// SetSystem sets the git config value for the key in the system config func (c *gitConfig) SetSystem(key, val string) (string, error) { return subprocess.SimpleExec("git", "config", "--system", key, val) }
// ListFromFile lists all of the git config values in the given config file func (c *gitConfig) ListFromFile(f string) (string, error) { return subprocess.SimpleExec("git", "config", "-l", "-f", f) }
// Version returns the git version func (c *gitConfig) Version() (string, error) { return subprocess.SimpleExec("git", "version") }
func UpdateIndex(file string) error { _, err := subprocess.SimpleExec("git", "update-index", "-q", "--refresh", file) return err }
// Find returns the git config value for the key func (c *gitConfig) FindLocal(val string) string { output, _ := subprocess.SimpleExec("git", "config", "--local", val) return output }
// FindSystem returns the git config value in system scope for the key func (c *gitConfig) FindSystem(val string) string { output, _ := subprocess.SimpleExec("git", "config", "--system", val) return output }