This repository has been archived by the owner on Sep 11, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 538
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1142 from EmrysMyrddin/feature/export-new-remote
git : allows to create a Remote without a Repository
- Loading branch information
Showing
4 changed files
with
82 additions
and
37 deletions.
There are no files selected for viewing
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,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) | ||
} |
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
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
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