CommitAll stages all changes in the working tree and creates a commit with the given message. If pathspec is non-empty, staging and the empty-commit check are scoped to that pathspec. The commit's author and committer are set to the provided name and email. Returns the new commit hash, or ErrEmptyCo
(ctx context.Context, path, pathspec, message, authorName, authorEmail string)
| 136 | // The commit's author and committer are set to the provided name and email. |
| 137 | // Returns the new commit hash, or ErrEmptyCommit if there are no changes to commit. |
| 138 | func CommitAll(ctx context.Context, path, pathspec, message, authorName, authorEmail string) (string, error) { |
| 139 | addArgs := []string{"add", "--all"} |
| 140 | statusArgs := []string{"status", "--porcelain"} |
| 141 | if pathspec != "" { |
| 142 | addArgs = append(addArgs, "--", pathspec) |
| 143 | statusArgs = append(statusArgs, "--", pathspec) |
| 144 | } |
| 145 | |
| 146 | if _, err := Run(ctx, path, addArgs...); err != nil { |
| 147 | return "", err |
| 148 | } |
| 149 | |
| 150 | status, err := Run(ctx, path, statusArgs...) |
| 151 | if err != nil { |
| 152 | return "", err |
| 153 | } |
| 154 | if status == "" { |
| 155 | return "", ErrEmptyCommit |
| 156 | } |
| 157 | |
| 158 | args := []string{ |
| 159 | "-c", "user.name=" + authorName, |
| 160 | "-c", "user.email=" + authorEmail, |
| 161 | "commit", "-m", message, |
| 162 | } |
| 163 | if _, err := Run(ctx, path, args...); err != nil { |
| 164 | return "", err |
| 165 | } |
| 166 | |
| 167 | return Hash(ctx, path, "HEAD") |
| 168 | } |
| 169 | |
| 170 | // FetchBranches fetches the specified branches from the remote repository. |
| 171 | // If a branch doesn't exist on the remote, it will be skipped without returning an error. |