forked from go-git/go-git
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
_examples: Add git clone using ssh-agent
Signed-off-by: Paulo Gomes <paulo.gomes@suse.com>
- Loading branch information
Showing
2 changed files
with
37 additions
and
0 deletions.
There are no files selected for viewing
File renamed without changes.
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 |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
|
||
git "github.com/go-git/go-git/v5" | ||
. "github.com/go-git/go-git/v5/_examples" | ||
"github.com/go-git/go-git/v5/plumbing/transport/ssh" | ||
) | ||
|
||
func main() { | ||
CheckArgs("<url>", "<directory>") | ||
url, directory := os.Args[1], os.Args[2] | ||
|
||
authMethod, err := ssh.NewSSHAgentAuth("git") | ||
CheckIfError(err) | ||
|
||
// Clone the given repository to the given directory | ||
Info("git clone %s ", url) | ||
|
||
r, err := git.PlainClone(directory, false, &git.CloneOptions{ | ||
Auth: authMethod, | ||
URL: url, | ||
Progress: os.Stdout, | ||
}) | ||
CheckIfError(err) | ||
|
||
// ... retrieving the branch being pointed by HEAD | ||
ref, err := r.Head() | ||
CheckIfError(err) | ||
// ... retrieving the commit object | ||
commit, err := r.CommitObject(ref.Hash()) | ||
CheckIfError(err) | ||
|
||
fmt.Println(commit) | ||
} |