Beispiel #1
0
func handleCommit(ctx *cli.Context, client *daemon.Client) error {
	message := ctx.String("message")
	if message == "" {
		message = fmt.Sprintf("Update on %s", time.Now().String())
	}
	status, err := client.Status()
	if err != nil {
		return err
	}

	statusCmt := status.Commit
	if statusCmt == nil {
		return fmt.Errorf("Empty status commit in response.")
	}

	commitCnt := len(statusCmt.Changeset)
	if commitCnt == 0 {
		fmt.Println("Nothing to commit.")
		return nil
	}
	if commitCnt != 1 {
		fmt.Printf("%d changes commited.\n", commitCnt)
	} else {
		fmt.Printf("%d change commited.\n", commitCnt)
	}

	return client.MakeCommit(message)
}
Beispiel #2
0
func handleStatus(ctx *cli.Context, client *daemon.Client) error {
	status, err := client.Status()
	if err != nil {
		return err
	}

	statusCmt := status.Commit
	if statusCmt == nil {
		return fmt.Errorf("Empty status commit in response.")
	}

	checkpoints := statusCmt.Checkpoints
	if len(checkpoints) == 0 {
		fmt.Println("Nothing to commit.")
		return nil
	}

	userToChanges := make(map[id.ID]changeByType)
	for _, pckp := range checkpoints {
		byAuthor, ok := userToChanges[id.ID(pckp.Author)]
		if !ok {
			byAuthor = make(changeByType)
			userToChanges[id.ID(pckp.Author)] = byAuthor
		}

		byAuthor[pckp.Change] = append(byAuthor[pckp.Change], pckp)
	}

	for user, changesByuser := range userToChanges {
		fmt.Printf(
			"Changes by %s:\n",
			colors.Colorize(string(user), colors.Magenta),
		)
		printChangesByUser(changesByuser)
	}

	return nil
}