-
Notifications
You must be signed in to change notification settings - Fork 114
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add option to push to gh-pages #73
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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,62 @@ | ||
package git | ||
|
||
import ( | ||
"fmt" | ||
"io/ioutil" | ||
"os" | ||
"os/exec" | ||
) | ||
|
||
type Git struct{} | ||
|
||
// AddWorktree creates a new Git worktree with a detached HEAD for the given committish and returns its path. | ||
func (g *Git) AddWorktree(workingDir string, committish string) (string, error) { | ||
dir, err := ioutil.TempDir("", "chart-releaser-") | ||
if err != nil { | ||
return "", err | ||
} | ||
command := exec.Command("git", "worktree", "add", "--detach", dir, committish) | ||
|
||
if err := runCommand(workingDir, command); err != nil { | ||
return "", err | ||
} | ||
return dir, nil | ||
} | ||
|
||
// RemoveWorktree removes the Git worktree with the given path. | ||
func (g *Git) RemoveWorktree(workingDir string, path string) error { | ||
command := exec.Command("git", "worktree", "remove", path, "--force") | ||
return runCommand(workingDir, command) | ||
} | ||
|
||
// Add runs 'git add' with the given args. | ||
func (g *Git) Add(workingDir string, args ...string) error { | ||
if len(args) == 0 { | ||
return fmt.Errorf("no args specified") | ||
} | ||
addArgs := []string{"add"} | ||
addArgs = append(addArgs, args...) | ||
command := exec.Command("git", addArgs...) | ||
return runCommand(workingDir, command) | ||
} | ||
|
||
// Commit runs 'git commit' with the given message. the commit is signed off. | ||
func (g *Git) Commit(workingDir string, message string) error { | ||
command := exec.Command("git", "commit", "--message", message, "--signoff") | ||
return runCommand(workingDir, command) | ||
} | ||
|
||
// Push runs 'git push' with the given args. | ||
func (g *Git) Push(workingDir string, args ...string) error { | ||
pushArgs := []string{"push"} | ||
pushArgs = append(pushArgs, args...) | ||
command := exec.Command("git", pushArgs...) | ||
return runCommand(workingDir, command) | ||
} | ||
|
||
func runCommand(workingDir string, command *exec.Cmd) error { | ||
command.Dir = workingDir | ||
command.Stdout = os.Stdout | ||
command.Stderr = os.Stderr | ||
return command.Run() | ||
} |
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
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@unguiculus what do you think about using https://github.com/go-git/go-git instead of our own package that shells out?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We had used that in a client project and dropped it. We hit bugs and had various issues with it and it covers only a small subset of Git which wasn't enough for us. Plus, it's not really straight forward to use. I'd rather not use it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
'worktree' is not supported BTW.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I saw that in the compatibility doc, but read through https://github.com/go-git/go-git/blob/master/worktree_test.go, which led me to think the doc just wasn't updated. But I don't have any real world experience using that package, so definitely trust your judgement 👍 My main thought was it could be cool to be able to run this without git as a dependency. Maybe something to reevaluate later?