aboutsummaryrefslogtreecommitdiffstats
path: root/_examples
diff options
context:
space:
mode:
authorValentin Cocaud <v.cocaud@gmail.com>2019-05-03 11:54:28 +0200
committerValentin Cocaud <v.cocaud@gmail.com>2019-06-17 22:51:37 +0200
commitb4fba7ede146be79cf65b89975250cf6869fb409 (patch)
treef7444e0731d559859de6d5739983f4ec9b40ab12 /_examples
parenta35ce6e8ee8e0fc5449c0fd10d45d0bddc894edc (diff)
downloadgo-git-b4fba7ede146be79cf65b89975250cf6869fb409.tar.gz
git : allows to create a Remote without a Repository
Signed-off-by: Valentin Cocaud <v.cocaud@gmail.com>
Diffstat (limited to '_examples')
-rw-r--r--_examples/ls-remote/main.go42
1 files changed, 42 insertions, 0 deletions
diff --git a/_examples/ls-remote/main.go b/_examples/ls-remote/main.go
new file mode 100644
index 0000000..68c0454
--- /dev/null
+++ b/_examples/ls-remote/main.go
@@ -0,0 +1,42 @@
+package main
+
+import (
+ "log"
+
+ "gopkg.in/src-d/go-git.v4"
+ "gopkg.in/src-d/go-git.v4/config"
+ "gopkg.in/src-d/go-git.v4/storage/memory"
+)
+
+// Retrieve remote tags without cloning repository
+func main() {
+
+ // Create the remote with repository URL
+ rem := git.NewRemote(memory.NewStorage(), &config.RemoteConfig{
+ Name: "origin",
+ URLs: []string{"https://github.com/Zenika/MARCEL"},
+ })
+
+ log.Print("Fetching tags...")
+
+ // We can then use every Remote functions to retrieve wanted informations
+ refs, err := rem.List(&git.ListOptions{})
+ if err != nil {
+ log.Fatal(err)
+ }
+
+ // Filters the references list and only keeps tags
+ var tags []string
+ for _, ref := range refs {
+ if ref.Name().IsTag() {
+ tags = append(tags, ref.Name().Short())
+ }
+ }
+
+ if len(tags) == 0 {
+ log.Println("No tags!")
+ return
+ }
+
+ log.Printf("Tags found: %v", tags)
+}