git

package
v0.0.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 11, 2016 License: MIT Imports: 10 Imported by: 0

README

Git

This application is inspired by hub, but is much simpler. It can do the following:

  • expand clone command
  • clone to your workspace regardless of your current directory
  • add githooks

TODO

  • support default http clone url in remote.go's NewFromURL
  • support default ssh clone url in remote.go's NewFromURL
  • handle non default ssh port in GetSSH
  • detect workspace, config -> gopath -> askuser input current dir and clone to workspace
  • clone project by host order if using short url, and let user choose if there are same project on multiple hosts
  • cleanup duplicated code remote.go, all the checking and error logging can be merged

Documentation

Index

Constants

View Source
const (
	// DefaultSSHPort 22
	DefaultSSHPort = 22
	// DefaultHTTPPort 80
	DefaultHTTPPort = 80
)

Variables

View Source
var DefaultHosts = [...]Host{
	*NewHost("github.com"),
	*NewHost("gitlab.com"),
	*NewHost("bitbucket.org"),
	*NewHost("coding.net", "git.coding.net"),
	*NewHost("git.oschina.net"),
}

DefaultHosts include common public git hosts TODO: maybe use an string array to construct this is better

Functions

func GetAllHostsMap

func GetAllHostsMap() map[string]Host

GetAllHostsMap return a map with host name(url) as key

func GetCloneDirectory

func GetCloneDirectory(r Remote) string

GetCloneDirectory return path for clone destination

func GetRepoBasePath

func GetRepoBasePath() string

GetRepoBasePath return path in ordr of : config, GOPATH, current directory

func ReadConfigFile

func ReadConfigFile()

ReadConfigFile read user defined hosts in .ayi.yml

Types

type Host

type Host struct {
	URL          string
	SupportHTTPS bool
	SupportSSH   bool
	HTTPPort     int
	SSHPort      int
	SSHURL       string
}

Host represent a remote git host server like github.com, gitlab.com

func GetAllHosts

func GetAllHosts() []Host

GetAllHosts return an array of hosts

func NewHost

func NewHost(urls ...string) *Host

NewHost return a new Host object with default config https://golang.org/doc/effective_go.html#allocation_new TODO: why use poniter instead of return object directly, The Go Programming Language P32 2.3.2 pointer

type Remote

type Remote struct {
	// Name is origin, upstream etc
	Name string
	// Protocol is http, https, ssh
	Protocol string
	// Host is the git host provider domain name, like github.com
	// TODO: store a HostURL and embed a Host object
	Host string
	// Port is used for remote that does not use default ssh port
	Port int
	// Owner is user name or organization name
	Owner string
	// Repo is repository name
	Repo string
	// SupportHTTPS shows if the host is using HTTPS
	// TODO: change is to a method
	SupportHTTPS bool
	// SSH clone url can ignore config for known hosts
	IgnoreConfig bool
}

Remote represents a remote git repository

func NewFromURL

func NewFromURL(url string) (Remote, error)

NewFromURL returns a remote based on the url, which could be - url in browser https://github.com/dyweb/Ayi - import url, like import "github.com/dyweb/Ayi/util" - short url dyweb/Ayi, default host would be github, but it can also use GitLab based on your config

func (Remote) GetSSH

func (r Remote) GetSSH() string

GetSSH return the ssh clone address

type Repo

type Repo struct {
	Remote    Remote
	LocalPath string
}

Repo is a repository with local path and remote

func Clone

func Clone(r Remote) (Repo, error)

Clone clones a remote git repo

func CloneFromURL

func CloneFromURL(repoURL string) (Repo, error)

CloneFromURL will clone a repository based on short url or normal git clone url

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL