-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feature: Ability to display changed files from the latest commit (#7)
- Loading branch information
1 parent
28277f6
commit ecfba94
Showing
3 changed files
with
68 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"strings" | ||
|
||
"github.com/go-git/go-git/v5" | ||
) | ||
|
||
func actionChanges() error { | ||
repo, err := git.PlainOpen(".") | ||
if err != nil { | ||
return err | ||
} | ||
|
||
ref, err := repo.Head() | ||
if err != nil { | ||
return err | ||
} | ||
|
||
commit, err := repo.CommitObject(ref.Hash()) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
stats, err := commit.Stats() | ||
if err != nil { | ||
return err | ||
} | ||
|
||
var changedFiles []string | ||
|
||
for _, stat := range stats { | ||
changedFiles = append(changedFiles, stat.Name) | ||
} | ||
|
||
if Depth == 0 { | ||
fmt.Printf("%s\n", strings.Join(changedFiles, " ")) | ||
} else { | ||
var res []string | ||
keys := make(map[string]int) | ||
|
||
for _, f := range changedFiles { | ||
if _, ok := keys[f]; !ok { | ||
keys[f] = 1 | ||
filepath := strings.Split(f, "/") | ||
|
||
if len(filepath) >= Depth { | ||
filepath = filepath[0:Depth] | ||
} | ||
|
||
res = append(res, strings.Join(filepath, "/")) | ||
} | ||
} | ||
|
||
fmt.Printf("%s\n", strings.Join(res, " ")) | ||
} | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters