Skip to content

Commit

Permalink
add status message for diff entries (#138)
Browse files Browse the repository at this point in the history
  • Loading branch information
JunNishimura committed Jun 24, 2023
1 parent edc88c8 commit 381c116
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions cmd/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,27 @@ var statusCmd = &cobra.Command{
}
}

// compare index with HEAD commit
treeObj, err := object.GetObject(client.RootGoitPath, client.Head.Commit.Tree)
if err != nil {
return fmt.Errorf("fail to get tree object: %w", err)
}
tree, err := object.NewTree(client.RootGoitPath, treeObj)
if err != nil {
return fmt.Errorf("fail to get tree: %w", err)
}
diffEntries, err := client.Idx.DiffWithTree(tree)
if err != nil {
return fmt.Errorf("fail to get diff entries: %w", err)
}

// construct message
if len(diffEntries) > 0 {
statusMessage += "\nChanges to be committed:\n (use 'goit restore --staged <file>...' to unstage)\n"
for _, diffEntry := range diffEntries {
statusMessage += color.GreenString("\t%-13s%s\n", diffEntry.Dt, diffEntry.Entry.Path)
}
}
if len(modifiedFiles) > 0 {
statusMessage += "\nChanges not staged for commit:\n (use 'goit add/rm <file>...' to update what will be committed)\n (use 'goit restore <file>...' to discard changes in working directory)\n"
for _, file := range modifiedFiles {
Expand Down

0 comments on commit 381c116

Please sign in to comment.