-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat(repository): introduce repo update functions This makes it possible for addon writers to interact with the repository via: 1. creating a branch 2. using the branch 3. adding files to staging 4. commit files 5. push changes to server Signed-off-by: David Zager <[email protected]> Signed-off-by: Ankur Mundra <[email protected]> * feat(repository): add user + email to gitconfig Signed-off-by: Ankur Mundra <[email protected]> * repo capabilities for git & svn Signed-off-by: Ankur Mundra <[email protected]> * renamed internal function, not exported Signed-off-by: Ankur Mundra <[email protected]> Signed-off-by: David Zager <[email protected]> Signed-off-by: Ankur Mundra <[email protected]> Co-authored-by: David Zager <[email protected]>
- Loading branch information
1 parent
91dcb11
commit b6cf85c
Showing
3 changed files
with
121 additions
and
28 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 |
---|---|---|
|
@@ -13,13 +13,11 @@ import ( | |
"strings" | ||
) | ||
|
||
// | ||
// Git repository. | ||
type Git struct { | ||
SCM | ||
} | ||
|
||
// | ||
// Validate settings. | ||
func (r *Git) Validate() (err error) { | ||
u := GitURL{} | ||
|
@@ -43,7 +41,6 @@ func (r *Git) Validate() (err error) { | |
return | ||
} | ||
|
||
// | ||
// Fetch clones the repository. | ||
func (r *Git) Fetch() (err error) { | ||
url := r.URL() | ||
|
@@ -84,15 +81,61 @@ func (r *Git) Fetch() (err error) { | |
return | ||
} | ||
|
||
// | ||
// Branch creates a branch with the given name if not exist and switch to it | ||
func (r *Git) Branch(name string) (err error) { | ||
cmd := command.Command{Path: "/usr/bin/git"} | ||
cmd.Dir = r.Path | ||
cmd.Options.Add("checkout", name) | ||
err = cmd.Run() | ||
if err != nil { | ||
cmd = command.Command{Path: "/usr/bin/git"} | ||
cmd.Dir = r.Path | ||
cmd.Options.Add("checkout", "-b", name) | ||
} | ||
r.Application.Repository.Branch = name | ||
return cmd.Run() | ||
} | ||
|
||
// addFiles adds files to staging area | ||
func (r *Git) addFiles(files []string) (err error) { | ||
cmd := command.Command{Path: "/usr/bin/git"} | ||
cmd.Dir = r.Path | ||
cmd.Options.Add("add", files...) | ||
return cmd.Run() | ||
} | ||
|
||
// Commit files and push to remote | ||
func (r *Git) Commit(files []string, msg string) (err error) { | ||
err = r.addFiles(files) | ||
if err != nil { | ||
return err | ||
} | ||
cmd := command.Command{Path: "/usr/bin/git"} | ||
cmd.Dir = r.Path | ||
cmd.Options.Add("commit") | ||
cmd.Options.Add("--message", msg) | ||
err = cmd.Run() | ||
if err != nil { | ||
return err | ||
} | ||
return r.push() | ||
} | ||
|
||
// push changes to server | ||
func (r *Git) push() (err error) { | ||
cmd := command.Command{Path: "/usr/bin/git"} | ||
cmd.Dir = r.Path | ||
cmd.Options.Add("push", "--set-upstream", "origin", r.Application.Repository.Branch) | ||
return cmd.Run() | ||
} | ||
|
||
// URL returns the parsed URL. | ||
func (r *Git) URL() (u GitURL) { | ||
u = GitURL{} | ||
_ = u.With(r.Application.Repository.URL) | ||
return | ||
} | ||
|
||
// | ||
// writeConfig writes config file. | ||
func (r *Git) writeConfig() (err error) { | ||
path := pathlib.Join(HomeDir, ".gitconfig") | ||
|
@@ -116,7 +159,10 @@ func (r *Git) writeConfig() (err error) { | |
if err != nil { | ||
return | ||
} | ||
s := "[credential]\n" | ||
s := "[user]\n" | ||
s += "name = Konveyor Dev\n" | ||
s += "email = [email protected]\n" | ||
s += "[credential]\n" | ||
s += "helper = store\n" | ||
s += "[http]\n" | ||
s += fmt.Sprintf("sslVerify = %t\n", !insecure) | ||
|
@@ -135,7 +181,6 @@ func (r *Git) writeConfig() (err error) { | |
return | ||
} | ||
|
||
// | ||
// writeCreds writes credentials (store) file. | ||
func (r *Git) writeCreds(id *api.Identity) (err error) { | ||
if id.User == "" || id.Password == "" { | ||
|
@@ -184,7 +229,6 @@ func (r *Git) writeCreds(id *api.Identity) (err error) { | |
return | ||
} | ||
|
||
// | ||
// proxy builds the proxy. | ||
func (r *Git) proxy() (proxy string, err error) { | ||
kind := "" | ||
|
@@ -236,7 +280,6 @@ func (r *Git) proxy() (proxy string, err error) { | |
return | ||
} | ||
|
||
// | ||
// checkout ref. | ||
func (r *Git) checkout() (err error) { | ||
branch := r.Application.Repository.Branch | ||
|
@@ -254,7 +297,6 @@ func (r *Git) checkout() (err error) { | |
return | ||
} | ||
|
||
// | ||
// GitURL git clone URL. | ||
type GitURL struct { | ||
Raw string | ||
|
@@ -263,7 +305,6 @@ type GitURL struct { | |
Path string | ||
} | ||
|
||
// | ||
// With populates the URL. | ||
func (r *GitURL) With(u string) (err error) { | ||
r.Raw = u | ||
|
@@ -291,7 +332,6 @@ func (r *GitURL) With(u string) (err error) { | |
return | ||
} | ||
|
||
// | ||
// String representation. | ||
func (r *GitURL) String() string { | ||
return r.Raw | ||
|
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