-
-
Notifications
You must be signed in to change notification settings - Fork 394
Use git clone for pkgbuild downloading #297
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
Closed
Closed
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 hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -6,9 +6,28 @@ import ( | |
| "net/http" | ||
| "os" | ||
| "os/exec" | ||
| "path/filepath" | ||
| "strings" | ||
| ) | ||
|
|
||
| // Decide what download method to use: | ||
| // Use the config option when the destination does not already exits | ||
| // If .git exists in the destination uer git | ||
| // Otherwise use a tarrball | ||
| func shouldUseGit(path string) bool { | ||
| _, err := os.Stat(path) | ||
| if os.IsNotExist(err) { | ||
| return config.GitClone | ||
| } | ||
|
|
||
| _, err = os.Stat(filepath.Join(path, ".git")) | ||
| if os.IsNotExist(err) { | ||
| return false | ||
| } | ||
|
|
||
| return true | ||
| } | ||
|
|
||
| func downloadFile(path string, url string) (err error) { | ||
| // Create the file | ||
| out, err := os.Create(path) | ||
|
|
@@ -29,6 +48,37 @@ func downloadFile(path string, url string) (err error) { | |
| return err | ||
| } | ||
|
|
||
| func gitDownload(url string, path string, name string) error { | ||
| _, err := os.Stat(filepath.Join(path, name, ".git")) | ||
| if os.IsNotExist(err) { | ||
| err = passToGit(path, "clone", url, name) | ||
| if err != nil { | ||
| return fmt.Errorf("error cloning %s", name) | ||
| } | ||
|
|
||
| return nil | ||
| } else if err != nil { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No need for this
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. True true, I'll change it in a bit. |
||
| return fmt.Errorf("error reading %s", filepath.Join(path, name, ".git")) | ||
| } | ||
|
|
||
| err = passToGit(filepath.Join(path, name), "fetch") | ||
| if err != nil { | ||
| return fmt.Errorf("error fetching %s", name) | ||
| } | ||
|
|
||
| err = passToGit(filepath.Join(path, name), "reset", "--hard", "HEAD") | ||
| if err != nil { | ||
| return fmt.Errorf("error reseting %s", name) | ||
| } | ||
|
|
||
| err = passToGit(filepath.Join(path, name), "merge", "--no-edit", "--ff") | ||
| if err != nil { | ||
| return fmt.Errorf("error merging %s", name) | ||
| } | ||
|
|
||
| return nil | ||
| } | ||
|
|
||
| // DownloadAndUnpack downloads url tgz and extracts to path. | ||
| func downloadAndUnpack(url string, path string, trim bool) (err error) { | ||
| err = os.MkdirAll(path, 0755) | ||
|
|
@@ -129,8 +179,18 @@ func getPkgbuildsfromAUR(pkgs []string, dir string) (err error) { | |
| } | ||
|
|
||
| for _, pkg := range aq { | ||
| downloadAndUnpack(baseURL+aq[0].URLPath, dir, false) | ||
| fmt.Println(bold(green(arrow)), bold(green("Downloaded")), bold(magenta(pkg.Name)), bold(green("from AUR"))) | ||
| var err error | ||
| if shouldUseGit(filepath.Join(dir, pkg.PackageBase)) { | ||
| err = gitDownload(baseURL+"/"+pkg.PackageBase+".git", dir, pkg.PackageBase) | ||
| } else { | ||
| err = downloadAndUnpack(baseURL+aq[0].URLPath, dir, false) | ||
| } | ||
|
|
||
| if err != nil { | ||
| fmt.Println(err) | ||
| } else { | ||
| fmt.Println(bold(green(arrow)), bold(green("Downloaded")), bold(magenta(pkg.Name)), bold(green("from AUR"))) | ||
| } | ||
| } | ||
|
|
||
| return | ||
|
|
||
This file contains hidden or 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 hidden or 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.
Maybe pick a different name for this
_argsvariable? I skimmed quickly through the code and didn't find other variables named similarly (starting with an underline).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 would rather not have to have two separate variables at all like in the other passTo* functions but it didn't work like that. If you've got a better method or name feel free to suggest one.