func deactivateGitConfig(args []string, info *Info) bool { var global bool var dir, gitDir, name string if len(args) == 2 { global = true name = args[0] } else if len(args) == 3 { dir = args[0] gitDir = getGitDir(dir) name = args[1] } else { return false } escapedDir := escapeDir(dir) values := storage.ReadStorage(SETTINGS, GIT_CONFIG, escapedDir) prefix := info.envdir + "=" for i, line := range values { if strings.HasPrefix(line, prefix) { var err error if global { _, err = util.ExecCommand("git", "config", "--global", name, strings.TrimPrefix(line, prefix)) } else { _, err = util.ExecCommand("git", gitDir, "config", name, strings.TrimPrefix(line, prefix)) } if err != nil { util.PrintErrorsContinue(err) } storage.WriteStorage(SETTINGS, GIT_CONFIG, escapedDir, append(values[:i], values[i+1:]...)) break } } return true }
func deactivateGitCheckout(args []string, info *Info) bool { if len(args) != 2 { return false } dir := escapeDir(args[0]) branches := storage.ReadStorage(SETTINGS, GIT_CHECKOUT, dir) prefix := info.envdir + "=" for i, line := range branches { if strings.HasPrefix(line, prefix) { util.ExecCommand("git", getGitDir(args[0]), "checkout", strings.TrimPrefix(line, prefix)) storage.WriteStorage(SETTINGS, GIT_CHECKOUT, dir, append(branches[:i], branches[i+1:]...)) break } } return true }
func activateGitCheckout(args []string, info *Info) bool { if len(args) != 2 { return false } branch, err := util.ExecCommand("git", getGitDir(args[0]), "rev-parse", "--abbrev-ref", "HEAD") if err != nil || len(branch) == 0 { util.PrintErrorMessageContinue("can't find branch message in " + args[0]) return false } dir := escapeDir(args[0]) branches := storage.ReadStorage(SETTINGS, GIT_CHECKOUT, dir) storage.WriteStorage(SETTINGS, GIT_CHECKOUT, dir, append(branches, info.envdir+"="+branch)) _, err = util.ExecCommand("git", getGitDir(args[0]), "checkout", args[1]) if err != nil { util.PrintErrorMessageContinue(fmt.Sprintf("can't checkout to %s in %s", args[1], args[0])) return false } return true }
func activateGitConfig(args []string, info *Info) bool { var global bool var dir, gitDir, name, value string if len(args) == 2 { global = true dir = util.GetCurrentPath() name = args[0] value = args[1] } else if len(args) == 3 { dir = args[0] name = args[1] value = args[2] } else { return false } gitDir = getGitDir(dir) var preValue string var err error if global { preValue, err = util.ExecCommand("git", "config", "--global", name) } else { preValue, err = util.ExecCommand("git", gitDir, "config", name) } if err != nil { util.PrintErrorMessageContinue(fmt.Sprintf("can't change config %s to %s in %s", name, value, dir)) return false } escapedDir := escapeDir(dir) values := storage.ReadStorage(SETTINGS, GIT_CONFIG, escapedDir) storage.WriteStorage(SETTINGS, GIT_CONFIG, escapedDir, append(values, info.envdir+"="+preValue)) if global { _, err = util.ExecCommand("git", "config", "--global", name, value) } else { _, err = util.ExecCommand("git", gitDir, "config", name, value) } if err != nil { util.PrintErrorMessageContinue(fmt.Sprintf("can't change config %s to %s in %s", name, value, dir)) return false } return true }