示例#1
0
// commitFiles adds file information to commit
func commitFiles(commit *meta.Commit, repo *meta.Repo, files map[string]int) {
	// Preallocation is the way to go
	commit.File = make([]meta.File, 0, len(files))
	for key, value := range files {
		if value == status.UNTRACKED || value == status.REMOVED {
			continue
		}
		s, err := crypto.SHA512(key)
		if err != nil {
			panic(err)
		}
		commit.File = append(commit.File, meta.File{xml.Name{"", "FILE"}, s, key})
	}
}
示例#2
0
// promptMessage prompts the user for the commit message
func promptMessage(commit *meta.Commit) error {
	fmt.Println("Enter a message for this commit:")
	buf, err := ioutil.ReadAll(os.Stdin)
	if err != nil {
		return err
	}
	commit.Message = strings.TrimSpace(string(buf))
	return nil
}
示例#3
0
// fillCommit fills a commit with all needed information
func fillCommit(commit *meta.Commit, repo *meta.Repo) error {
	files, err := status.GetFileStatus()
	if err != nil {
		return err
	}
	if status.IsClean(files, nil) {
		return fmt.Errorf("\x1b[32;1mNothing to commit\x1b[0m")
	}
	err = commitPrompt(commit)
	if err != nil {
		return err
	}
	commit.Timestamp = time.Now()
	commitFiles(commit, repo, files)
	return nil
}