@@ -28,6 +28,8 @@ type Command struct {
28
28
isAmend bool
29
29
}
30
30
31
+ // excludeFiles returns a list of files to be excluded from git operations.
32
+ // It prepends each file in the excludeList with the exclude and top options.
31
33
func (c * Command ) excludeFiles () []string {
32
34
var excludedFiles []string
33
35
for _ , f := range c .excludeList {
@@ -36,6 +38,8 @@ func (c *Command) excludeFiles() []string {
36
38
return excludedFiles
37
39
}
38
40
41
+ // diffNames generates the git command to list the names of changed files.
42
+ // It includes options to handle amended commits and staged changes.
39
43
func (c * Command ) diffNames () * exec.Cmd {
40
44
args := []string {
41
45
"diff" ,
@@ -57,6 +61,9 @@ func (c *Command) diffNames() *exec.Cmd {
57
61
)
58
62
}
59
63
64
+ // diffFiles generates the git command to show the differences between files.
65
+ // It includes options to ignore whitespace changes, use minimal diff algorithm,
66
+ // and set the number of context lines.
60
67
func (c * Command ) diffFiles () * exec.Cmd {
61
68
args := []string {
62
69
"diff" ,
@@ -80,6 +87,8 @@ func (c *Command) diffFiles() *exec.Cmd {
80
87
)
81
88
}
82
89
90
+ // hookPath generates the git command to get the path of the hooks directory.
91
+ // This is used to locate where git hooks are stored.
83
92
func (c * Command ) hookPath () * exec.Cmd {
84
93
args := []string {
85
94
"rev-parse" ,
@@ -93,6 +102,8 @@ func (c *Command) hookPath() *exec.Cmd {
93
102
)
94
103
}
95
104
105
+ // gitDir generates the git command to get the path of the git directory.
106
+ // This is used to determine the location of the .git directory.
96
107
func (c * Command ) gitDir () * exec.Cmd {
97
108
args := []string {
98
109
"rev-parse" ,
@@ -105,6 +116,8 @@ func (c *Command) gitDir() *exec.Cmd {
105
116
)
106
117
}
107
118
119
+ // commit generates the git command to create a commit with the provided message.
120
+ // It includes options to skip pre-commit hooks, sign off the commit, and handle amendments.
108
121
func (c * Command ) commit (val string ) * exec.Cmd {
109
122
args := []string {
110
123
"commit" ,
@@ -123,6 +136,8 @@ func (c *Command) commit(val string) *exec.Cmd {
123
136
)
124
137
}
125
138
139
+ // Commit creates a git commit with the provided message and returns the output or an error.
140
+ // It uses the commit method to generate the git command and execute it.
126
141
func (c * Command ) Commit (val string ) (string , error ) {
127
142
output , err := c .commit (val ).Output ()
128
143
if err != nil {
@@ -145,6 +160,9 @@ func (c *Command) GitDir() (string, error) {
145
160
// Diff compares the differences between two sets of data.
146
161
// It returns a string representing the differences and an error.
147
162
// If there are no differences, it returns an empty string and an error.
163
+ // DiffFiles compares the differences between two sets of data and returns the differences as a string and an error.
164
+ // It first lists the names of changed files and then shows the differences between them.
165
+ // If there are no staged changes, it returns an error message.
148
166
func (c * Command ) DiffFiles () (string , error ) {
149
167
output , err := c .diffNames ().Output ()
150
168
if err != nil {
@@ -162,6 +180,8 @@ func (c *Command) DiffFiles() (string, error) {
162
180
return string (output ), nil
163
181
}
164
182
183
+ // InstallHook installs the prepare-commit-msg hook if it doesn't already exist.
184
+ // It retrieves the hooks directory path, checks if the hook file exists, and writes the hook file with executable permissions.
165
185
func (c * Command ) InstallHook () error {
166
186
hookPath , err := c .hookPath ().Output ()
167
187
if err != nil {
@@ -182,6 +202,8 @@ func (c *Command) InstallHook() error {
182
202
return os .WriteFile (target , content , 0o755 ) //nolint:gosec
183
203
}
184
204
205
+ // UninstallHook removes the prepare-commit-msg hook if it exists.
206
+ // It retrieves the hooks directory path, checks if the hook file exists, and removes the hook file.
185
207
func (c * Command ) UninstallHook () error {
186
208
hookPath , err := c .hookPath ().Output ()
187
209
if err != nil {
@@ -195,6 +217,8 @@ func (c *Command) UninstallHook() error {
195
217
return os .Remove (target )
196
218
}
197
219
220
+ // New creates a new Command object with the provided options.
221
+ // It applies each option to the config object and initializes the Command object with the configurations.
198
222
func New (opts ... Option ) * Command {
199
223
// Instantiate a new config object with default values
200
224
cfg := & config {}
0 commit comments