1

I am writing a go-lang app and I need to:

  1. Go to the sibling directory tried with:

    exec.Command("/bin/sh", "-c", "cd ..").Output()

  2. And clone/update GitHub private repository: git clone ....GitHub repository

I cannot accomplish neither of those tasks. I tried GitHub/libgit2/git2go but on Ubuntu 16.04 libgit2 cannot understand https.

Thank you for any help.

Svitlana
  • 2,324
  • 4
  • 22
  • 31
  • Changing directories in another instance of `/bin/sh` doesn't change your working directory. Also, why not just call `git` directly? – JimB Oct 26 '16 at 18:45
  • Sorry, for posting dummy questions again, but I run go run main.go in "/generator", but I need to go to sibling dir or I can hardcode dir /home/svitlana/go/src/realsiter/realster and run there git pull https://github – Svitlana Oct 26 '16 at 18:47
  • 1
    Executing a new shell and changing _its_ directory does nothing. You can use `os.Chdir` if you want to change the working directory of your process. But again, why not just execute `git pull` directly, rather than trying to use various libgit2 bindings? – JimB Oct 26 '16 at 18:55
  • a good idea :-). And how to specify auth info? – Svitlana Oct 26 '16 at 19:05
  • executable file not found in $PATH – Svitlana Oct 26 '16 at 19:13
  • 1
    You can use ssh, which will fetch your key from an agent. If you require https access, you can use a netrc file or other various options: https://stackoverflow.com/questions/5343068/is-there-a-way-to-skip-password-typing-when-using-https-on-github – JimB Oct 26 '16 at 19:22
  • Thank you, Jim. Already reading, hope to get it done. Thank you for your time! – Svitlana Oct 26 '16 at 19:25

1 Answers1

0

Credits comes to @JimB :-)

 func update_ghub(wg *sync.WaitGroup) {
    var (
        cmdOut []byte
        err    error
    )
    err = os.Chdir("/home/svitlana/go/src/realsiter/realster")
    if err != nil {
        log.Fatalln(err)
    }

    cmdName := "git"
    cmdArgs := []string{"pull"}

    if cmdOut, err = exec.Command(cmdName, cmdArgs...).Output(); err != nil {
        fmt.Fprintln(os.Stderr, "There was an error running git rev-parse command: ", err)
        os.Exit(1)
    }
    sha := string(cmdOut)
    fmt.Println("Response:", sha)
    wg.Done()
}
Svitlana
  • 2,324
  • 4
  • 22
  • 31