PHANTOM
🇮🇳 IN
Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -253,10 +253,16 @@ func handleConfig(option, value string) bool {
config.AnswerUpgrade = value
case "noanswerupgrade":
config.AnswerUpgrade = ""
case "gitclone":
config.GitClone = true
case "nogitclone":
config.GitClone = false
case "gpgflags":
config.GpgFlags = value
case "mflags":
config.MFlags = value
case "gitflags":
config.GitFlags = value
case "builddir":
config.BuildDir = value
case "editor":
Expand Down Expand Up @@ -557,3 +563,15 @@ func passToMakepkg(dir string, args ...string) (err error) {
}
return
}

func passToGit(dir string, _args ...string) (err error) {

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 _args variable? I skimmed quickly through the code and didn't find other variables named similarly (starting with an underline).

Copy link
Contributor Author

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.

gitflags := strings.Fields(config.GitFlags)
args := []string{"-C", dir}
args = append(args, gitflags...)
args = append(args, _args...)

cmd := exec.Command(config.GitBin, args...)
cmd.Stdin, cmd.Stdout, cmd.Stderr = os.Stdin, os.Stdout, os.Stderr
err = cmd.Run()
return
}
4 changes: 4 additions & 0 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ type Configuration struct {
GpgFlags string `json:"gpgflags"`
MFlags string `json:"mflags"`
SortBy string `json:"sortby"`
GitFlags string `json:"gitflags"`
RequestSplitN int `json:"requestsplitn"`
SearchMode int `json:"-"`
SortMode int `json:"sortmode"`
Expand All @@ -50,6 +51,7 @@ type Configuration struct {
NoConfirm bool `json:"-"`
Devel bool `json:"devel"`
CleanAfter bool `json:"cleanAfter"`
GitClone bool `json:"gitclone"`
}

var version = "3.373"
Expand Down Expand Up @@ -138,6 +140,7 @@ func defaultSettings(config *Configuration) {
config.PacmanConf = "/etc/pacman.conf"
config.GpgFlags = ""
config.MFlags = ""
config.GitFlags = ""
config.SortMode = BottomUp
config.SortBy = "votes"
config.SudoLoop = false
Expand All @@ -151,6 +154,7 @@ func defaultSettings(config *Configuration) {
config.AnswerClean = ""
config.AnswerEdit = ""
config.AnswerUpgrade = ""
config.GitClone = true
}

// Editor returns the preferred system editor.
Expand Down
64 changes: 62 additions & 2 deletions download.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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 {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need for this else (and the next one), since the blocks end with a return.

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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)
Expand Down Expand Up @@ -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
Expand Down
8 changes: 7 additions & 1 deletion install.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"os"
"os/exec"
"path/filepath"
"strconv"
"strings"

Expand Down Expand Up @@ -556,7 +557,12 @@ func downloadPkgBuilds(pkgs []*rpc.Pkg, targets stringSet, bases map[string][]*r

fmt.Printf(str, k+1, len(pkgs), formatPkgbase(pkg, bases))

err := downloadAndUnpack(baseURL+pkg.URLPath, config.BuildDir, false)
var err error
if shouldUseGit(filepath.Join(config.BuildDir, pkg.PackageBase)) {
err = gitDownload(baseURL+"/"+pkg.PackageBase+".git", config.BuildDir, pkg.PackageBase)
} else {
err = downloadAndUnpack(baseURL+pkg.URLPath, config.BuildDir, false)
}
if err != nil {
return err
}
Expand Down
2 changes: 2 additions & 0 deletions parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,8 @@ func hasParam(arg string) bool {
return true
case "gpgflags":
return true
case "gitflags":
return true
case "builddir":
return true
case "editor":
Expand Down