This repository was archived by the owner on Sep 11, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 534
git : allows to create a Remote without a Repository #1142
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 |
---|---|---|
|
@@ -45,7 +45,10 @@ type Remote struct { | |
s storage.Storer | ||
} | ||
|
||
func newRemote(s storage.Storer, c *config.RemoteConfig) *Remote { | ||
// NewRemote creates a new Remote. | ||
// The intended purpose is to use the Remote for tasks such as listing remote references (like using git ls-remote). | ||
// Otherwise Remotes should be created via the use of a Repository. | ||
func NewRemote(s storage.Storer, c *config.RemoteConfig) *Remote { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can you document the new exported function? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. sorry for the late response, I have added the documentation |
||
return &Remote{s: s, c: c} | ||
} | ||
|
||
|
This file contains hidden or 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 hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.