-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
Bumper: Allow user to specify working directory for git push #19159
Bumper: Allow user to specify working directory for git push #19159
Conversation
These functions have been added as part of the bugzilla backporter tool. The GetAllClones function would return all the clones of a particular bug(including its parent, grandparent etc.), unlike the GetClones function which would return only the clones which were cloned from that particular bug. The GetRoot function would return the original bug which produced the clone even if that bug is a clone of a clone.
Hi @GeoBK. Thanks for your PR. I'm waiting for a kubernetes member to verify that this patch is reasonable to test. If it is, they should reply with Once the patch is verified, the new status will be reflected by the I understand the commands that are listed here. Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
694c9fe
to
fc230f6
Compare
prow/flagutil/git.go
Outdated
@@ -28,8 +29,8 @@ import ( | |||
// GitOptions holds options for interacting with git. | |||
type GitOptions struct { | |||
host string | |||
user string | |||
email string | |||
User string |
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.
So the use from bumper
is not the git
library. Although the options seem the same, they are different. We should have a separate struct for them that's not tied to this, unless we expect a single binary to use both?
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 dont understand what you mean by "So the use from bumper is not the git library".
I am using both git and bumper here(https://github.com/openshift/ci-tools/pull/1211/files#diff-4440cf6f38e6026b7a8028aa83c9f664R33)
Am I doing that wrong?
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.
moved this from git options into new class GitAuthorOptions in bumper.go
|
||
gitCmd := "git" | ||
gitArgs := []string{} | ||
if workingDir != "" { |
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.
If this might be used across even more functions in the future is it worth making something like (below)?
type GitCommand struct {
baseCommand string
workingDir string
args []string{}
}
func (gc GitCommand) Call(stdout, stderr io.Writer) error {
if gc.workingDir != "" {
gc.args = append(gc.args, fmt.Sprintf("--git-dir=%s/.git", gc.workingDir), fmt.Sprintf("--work-tree=%s", gc.workingDir))
}
c := exec.Command(gc.baseCommand, gc.args...)
c.Stdout = stdout
c.Stderr = stderr
return c.Run()
}
if err := Call(stdout, stderr, "git", "push", "-f", remote, fmt.Sprintf("HEAD:%s", remoteBranch)); err != nil { | ||
gitArgs := []string{} | ||
if workingDir != "" { | ||
gitArgs = append(gitArgs, fmt.Sprintf("--git-dir=%s/.git", workingDir), fmt.Sprintf("--work-tree=%s", workingDir)) |
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 think we can simplify the --git-dir=%s/.git --work-tree=%s
to -C %s
.
if workingDir != "" { | ||
gitArgs = append(gitArgs, fmt.Sprintf("--git-dir=%s/.git", workingDir), fmt.Sprintf("--work-tree=%s", workingDir)) | ||
} | ||
gitPushArgs := append(gitArgs, "push", "-f", remote, fmt.Sprintf("HEAD:%s", remoteBranch)) |
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.
IMO no need to introduce a new variable, just use gitArgs
(and because we're in GitPush
function, I'd even call it just args
.
// RunAndCommitIfNeeded makes a commit in the workingDir if there are | ||
// any changes resulting from the command execution. Returns true if a commit is made | ||
func RunAndCommitIfNeeded(stdout, stderr io.Writer, author, cmd string, args []string, workingDir string) (bool, error) { | ||
fullCommand := fmt.Sprintf("%s %s", filepath.Base(cmd), strings.Join(args, " ")) |
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.
Same comment like I had in the ci-tools PR - fullCommand
is used in logging. While reading logs, I want to see what the tool really does (calls cmd
) without prettyfing it with filepath.Base
.
/ok-to-test |
fc230f6
to
7227458
Compare
/label tide/merge-method-squash |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: GeoBK, stevekuznetsov The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
This change would