Пример #1
0
func main() {
	if len(os.Args) < 2 {
		displayHelp()
		return
	}

	//Check command
	//Add new commands to this list
	switch os.Args[1] {
	case "init":
		initialize.Initialize()
	case "commit":
		commit.Commit()
	case "status":
		status.Status()
	case "branch":
		if len(os.Args) >= 3 {
			branch.Branch(strings.Join(os.Args[2:], " "))
		} else {
			branch.Display()
		}
	//case "merge":
	case "log":
		log.Display()
	case "reset":
		reset.Reset()
	case "revert":
		if len(os.Args) != 3 {
			displayHelp()
			return
		}
		n, err := strconv.Atoi(os.Args[2])
		if err != nil {
			fmt.Println(err)
			os.Exit(2)
		}
		revert.Revert(n)
	case "delete":
		remove.Remove()
	//case "tutorial":
	case "help":
		displayHelp()
	default:
		displayHelp()
	}
}
Пример #2
0
// newBranch creates a new branch and returns a pointer to it
func newBranch(title string) (*meta.Branch, error) {
	repo, err := meta.Open()
	if err != nil {
		return nil, err
	}
	if repo.SetCurrent(title) == nil {
		err = repo.Write()
		if err != nil {
			return nil, err
		}
		fmt.Println("Switched to branch: \x1b[32;1m" + title + "\x1b[0m")
		revert.Revert(0)
		return nil, nil
	}
	current, _ := repo.Find(repo.Current)
	if current == nil {
		panic(fmt.Errorf("Repo is corrupt"))
	}
	branch := current.Copy()
	branch.Title = title
	branch.Parent = current.Title
	current.Child = append(current.Child, branch.Title)
	err = repo.AddBranch(branch)
	if err != nil {
		return nil, err
	}
	err = repo.SetCurrent(branch.Title)
	if err != nil {
		return nil, err
	}
	err = repo.Write()
	if err != nil {
		return nil, err
	}
	err = copyStash(current.Title, branch.Title)
	if err != nil {
		return nil, err
	}
	fmt.Println("Created new branch: \x1b[32;1m" + title + "\x1b[0m")
	return branch, nil
}
Пример #3
0
// Reset resets the state of the working directory to that
// of the last commit.
func Reset() {
	revert.Revert(0)
}