Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: go-git/go-git
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v5.2.0
Choose a base ref
...
head repository: go-git/go-git
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v5.3.0
Choose a head ref

Commits on Sep 30, 2020

  1. Add init.defaultBranch to the config

    Thomas Lazar committed Sep 30, 2020
    Copy the full SHA
    ec9b50d View commit details

Commits on Oct 9, 2020

  1. add some tests

    Thomas Lazar committed Oct 9, 2020
    Copy the full SHA
    125fb62 View commit details

Commits on Oct 13, 2020

  1. Copy the full SHA
    e0bd4e8 View commit details

Commits on Oct 20, 2020

  1. Merge pull request #184 from mikyk10/master

    git: worktree, Support relative submodule URL.
    mcuadros authored Oct 20, 2020
    Copy the full SHA
    15aedd2 View commit details

Commits on Oct 28, 2020

  1. Fix relative submodule resolution

    With the current behavior, the config will always hold the resolved,
    absolute URL, leavin the user of go-git no choice to determine whether
    the original URL is relative or not.
    
    This changes to employ relative URL resolution only when resolving
    a submodule to a repository to keep the correct configuration
    'unresolved' and intact.
    
    Change relative resolution using `filepath.Dir` to `path.Join` while
    parsing both the 'root' and the relative URL with `net/url.URL`.
    
    Adapt test to verify the new behavior.
    
    Re-fixes #184 (see comments).
    Axel Christ committed Oct 28, 2020
    Copy the full SHA
    81d429b View commit details

Commits on Oct 30, 2020

  1. Merge pull request #195 from adracus/fix.relative-submodules

    Fix relative submodule resolution
    mcuadros authored Oct 30, 2020
    Copy the full SHA
    e9c56de View commit details
  2. Merge pull request #178 from tomlazar/defaultbranch

    config: add init.defaultBranch to the config
    mcuadros authored Oct 30, 2020
    Copy the full SHA
    d525a51 View commit details

Commits on Dec 1, 2020

  1. Copy the full SHA
    51cbc24 View commit details

Commits on Jan 27, 2021

  1. Adding "object-format" and "filter" capabilities (#222)

    * plumbing: protocol/packp, Adding object-format and filter capabilities. Fixes #220
    rofc authored Jan 27, 2021
    Copy the full SHA
    c6c9b10 View commit details
  2. Add insecureSkipTLS and cabundle (#228)

    This PR add insecureSkipTLSVerify and cabundle to any remote http calls
    so that https repo with private CA signed can be used. This is the
    equivalent of https.sslVerify and GIT_SSL_CAINFO
    StrongMonkey authored Jan 27, 2021
    Copy the full SHA
    1b1a61a View commit details
  3. worktree: Don't remove root directory when cleaning (#230)

    When using a separate worktree directory while working on a bare
    repository, cleaning with CleanOptions{Dir: true} would also remove the
    root worktree directory if empty.
    
    Signed-off-by: Michael Hanselmann <public@hansmi.ch>
    hansmi authored Jan 27, 2021
    Copy the full SHA
    024d62b View commit details

Commits on Feb 9, 2021

  1. git: worktree_commit, just store objects not already stored (#224)

    * git: worktree_commit, just store objects not already stored
    jsteuer authored Feb 9, 2021
    Copy the full SHA
    c66023a View commit details

Commits on Mar 10, 2021

  1. Copy the full SHA
    4519f59 View commit details

Commits on Mar 11, 2021

  1. diff: Allow srcPrefix and dstPrefix to be configured (#265)

    * diff: Allow srcPrefix and dstPrefix to be configured
    
    The default behavior here remains the same, but this change does
    allow consumers of the UnifiedEncoder to set their own path prefixes
    which will override the defaults of a/ and b/.
    
    * Add unit test for src/dstPrefix in encoder
    yabberyabber authored Mar 11, 2021
    Copy the full SHA
    55ba7b2 View commit details

Commits on Mar 25, 2021

  1. add RequireRemoteRefs to PushOptions (#258)

    The git protocol itself uses a compare-and-swap mechanism, where changes
    send the old and new values and the change is only applied if the old
    value matches. This is used to implement the --force-with-lease feature
    in git push.
    
    go-git populates the `old` field with the current value of the ref that
    is read from the remote. We can implement a convenient (albeit more
    limited) form of the --force-with-lease feature just by allowing the
    caller to specify particular values for this ref.
    
    Callers can then implement complex multi-step atomic operations by
    reading the ref themselves at the start of the process, and passing to
    in RequireRemoteRefs at the end. This is also a suitable building block
    for implementing --force-with-lease (#101), which is mostly an exercise
    in computing the correct hash to require. Hence, this appears to be the
    most reasonable API to expose.
    asuffield authored Mar 25, 2021
    Copy the full SHA
    bf3471d View commit details

Commits on Mar 26, 2021

  1. transport: ssh, fix cloning large repositories (#272)

    * Fix cloning large repositories
    
    Ignore the error on close when the connection is already closed
    
    Fixes #70
    
    * Compatibility for go 1.13
    
    Because it's required by the pipeline
    
    * Add test for allowing to close a command when the client is already closed
    
    This test is for issue #70
    
    * Add debug information for broken test
    dcu authored Mar 26, 2021
    Copy the full SHA
    1f32838 View commit details
  2. plumbing: wire up contexts for Transport.AdvertisedReferences (#246)

    * plumbing: wire up contexts for Transport.AdvertisedReferences
    
    * add more tests for context wiring
    asuffield authored Mar 26, 2021
    Copy the full SHA
    e5bbc4d View commit details
  3. *: fix flaky test

    mcuadros committed Mar 26, 2021
    Copy the full SHA
    9d995cb View commit details
  4. Copy the full SHA
    4ac486c View commit details
  5. go modules updated

    mcuadros committed Mar 26, 2021
    Copy the full SHA
    b0ef4d4 View commit details

Commits on Mar 29, 2021

  1. Copy the full SHA
    d5ed15d View commit details
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -5,7 +5,7 @@ jobs:
strategy:
fail-fast: false
matrix:
go-version: [1.13.x, 1.14.x]
go-version: [1.15.x, 1.16.x]
platform: [ubuntu-latest, macos-latest, windows-latest]

runs-on: ${{ matrix.platform }}
96 changes: 95 additions & 1 deletion config/config.go
Original file line number Diff line number Diff line change
@@ -89,6 +89,13 @@ type Config struct {
Window uint
}

Init struct {
// DefaultBranch Allows overriding the default branch name
// e.g. when initializing a new repository or when cloning
// an empty repository.
DefaultBranch string
}

// Remotes list of repository remotes, the key of the map is the name
// of the remote, should equal to RemoteConfig.Name.
Remotes map[string]*RemoteConfig
@@ -98,6 +105,9 @@ type Config struct {
// Branches list of branches, the key is the branch name and should
// equal Branch.Name
Branches map[string]*Branch
// URLs list of url rewrite rules, if repo url starts with URL.InsteadOf value, it will be replaced with the
// key instead.
URLs map[string]*URL
// Raw contains the raw information of a config file. The main goal is
// preserve the parsed information from the original format, to avoid
// dropping unsupported fields.
@@ -110,6 +120,7 @@ func NewConfig() *Config {
Remotes: make(map[string]*RemoteConfig),
Submodules: make(map[string]*Submodule),
Branches: make(map[string]*Branch),
URLs: make(map[string]*URL),
Raw: format.New(),
}

@@ -223,6 +234,8 @@ const (
userSection = "user"
authorSection = "author"
committerSection = "committer"
initSection = "init"
urlSection = "url"
fetchKey = "fetch"
urlKey = "url"
bareKey = "bare"
@@ -233,6 +246,7 @@ const (
rebaseKey = "rebase"
nameKey = "name"
emailKey = "email"
defaultBranchKey = "defaultBranch"

// DefaultPackWindow holds the number of previous objects used to
// generate deltas. The value 10 is the same used by git command.
@@ -251,6 +265,7 @@ func (c *Config) Unmarshal(b []byte) error {

c.unmarshalCore()
c.unmarshalUser()
c.unmarshalInit()
if err := c.unmarshalPack(); err != nil {
return err
}
@@ -260,6 +275,10 @@ func (c *Config) Unmarshal(b []byte) error {
return err
}

if err := c.unmarshalURLs(); err != nil {
return err
}

return c.unmarshalRemotes()
}

@@ -313,6 +332,25 @@ func (c *Config) unmarshalRemotes() error {
c.Remotes[r.Name] = r
}

// Apply insteadOf url rules
for _, r := range c.Remotes {
r.applyURLRules(c.URLs)
}

return nil
}

func (c *Config) unmarshalURLs() error {
s := c.Raw.Section(urlSection)
for _, sub := range s.Subsections {
r := &URL{}
if err := r.unmarshal(sub); err != nil {
return err
}

c.URLs[r.Name] = r
}

return nil
}

@@ -344,6 +382,11 @@ func (c *Config) unmarshalBranches() error {
return nil
}

func (c *Config) unmarshalInit() {
s := c.Raw.Section(initSection)
c.Init.DefaultBranch = s.Options.Get(defaultBranchKey)
}

// Marshal returns Config encoded as a git-config file.
func (c *Config) Marshal() ([]byte, error) {
c.marshalCore()
@@ -352,6 +395,8 @@ func (c *Config) Marshal() ([]byte, error) {
c.marshalRemotes()
c.marshalSubmodules()
c.marshalBranches()
c.marshalURLs()
c.marshalInit()

buf := bytes.NewBuffer(nil)
if err := format.NewEncoder(buf).Encode(c.Raw); err != nil {
@@ -475,13 +520,40 @@ func (c *Config) marshalBranches() {
s.Subsections = newSubsections
}

func (c *Config) marshalURLs() {
s := c.Raw.Section(urlSection)
s.Subsections = make(format.Subsections, len(c.URLs))

var i int
for _, r := range c.URLs {
section := r.marshal()
// the submodule section at config is a subset of the .gitmodule file
// we should remove the non-valid options for the config file.
s.Subsections[i] = section
i++
}
}

func (c *Config) marshalInit() {
s := c.Raw.Section(initSection)
if c.Init.DefaultBranch != "" {
s.SetOption(defaultBranchKey, c.Init.DefaultBranch)
}
}

// RemoteConfig contains the configuration for a given remote repository.
type RemoteConfig struct {
// Name of the remote
Name string
// URLs the URLs of a remote repository. It must be non-empty. Fetch will
// always use the first URL, while push will use all of them.
URLs []string

// insteadOfRulesApplied have urls been modified
insteadOfRulesApplied bool
// originalURLs are the urls before applying insteadOf rules
originalURLs []string

// Fetch the default set of "refspec" for fetch operation
Fetch []RefSpec

@@ -542,7 +614,12 @@ func (c *RemoteConfig) marshal() *format.Subsection {
if len(c.URLs) == 0 {
c.raw.RemoveOption(urlKey)
} else {
c.raw.SetOption(urlKey, c.URLs...)
urls := c.URLs
if c.insteadOfRulesApplied {
urls = c.originalURLs
}

c.raw.SetOption(urlKey, urls...)
}

if len(c.Fetch) == 0 {
@@ -562,3 +639,20 @@ func (c *RemoteConfig) marshal() *format.Subsection {
func (c *RemoteConfig) IsFirstURLLocal() bool {
return url.IsLocalEndpoint(c.URLs[0])
}

func (c *RemoteConfig) applyURLRules(urlRules map[string]*URL) {
// save original urls
originalURLs := make([]string, len(c.URLs))
copy(originalURLs, c.URLs)

for i, url := range c.URLs {
if matchingURLRule := findLongestInsteadOfMatch(url, urlRules); matchingURLRule != nil {
c.URLs[i] = matchingURLRule.ApplyInsteadOf(c.URLs[i])
c.insteadOfRulesApplied = true
}
}

if c.insteadOfRulesApplied {
c.originalURLs = originalURLs
}
}
58 changes: 57 additions & 1 deletion config/config_test.go
Original file line number Diff line number Diff line change
@@ -4,6 +4,7 @@ import (
"io/ioutil"
"os"
"path/filepath"
"strings"

"github.com/go-git/go-git/v5/plumbing"
. "gopkg.in/check.v1"
@@ -37,6 +38,8 @@ func (s *ConfigSuite) TestUnmarshal(c *C) {
url = git@github.com:src-d/go-git.git
fetch = +refs/heads/*:refs/remotes/origin/*
fetch = +refs/pull/*:refs/remotes/origin/pull/*
[remote "insteadOf"]
url = https://github.com/kostyay/go-git.git
[remote "win-local"]
url = X:\\Git\\
[submodule "qux"]
@@ -46,6 +49,10 @@ func (s *ConfigSuite) TestUnmarshal(c *C) {
[branch "master"]
remote = origin
merge = refs/heads/master
[init]
defaultBranch = main
[url "ssh://git@github.com/"]
insteadOf = https://github.com/
`)

cfg := NewConfig()
@@ -62,7 +69,7 @@ func (s *ConfigSuite) TestUnmarshal(c *C) {
c.Assert(cfg.Committer.Name, Equals, "Richard Roe")
c.Assert(cfg.Committer.Email, Equals, "richard@example.com")
c.Assert(cfg.Pack.Window, Equals, uint(20))
c.Assert(cfg.Remotes, HasLen, 3)
c.Assert(cfg.Remotes, HasLen, 4)
c.Assert(cfg.Remotes["origin"].Name, Equals, "origin")
c.Assert(cfg.Remotes["origin"].URLs, DeepEquals, []string{"git@github.com:mcuadros/go-git.git"})
c.Assert(cfg.Remotes["origin"].Fetch, DeepEquals, []RefSpec{"+refs/heads/*:refs/remotes/origin/*"})
@@ -71,12 +78,14 @@ func (s *ConfigSuite) TestUnmarshal(c *C) {
c.Assert(cfg.Remotes["alt"].Fetch, DeepEquals, []RefSpec{"+refs/heads/*:refs/remotes/origin/*", "+refs/pull/*:refs/remotes/origin/pull/*"})
c.Assert(cfg.Remotes["win-local"].Name, Equals, "win-local")
c.Assert(cfg.Remotes["win-local"].URLs, DeepEquals, []string{"X:\\Git\\"})
c.Assert(cfg.Remotes["insteadOf"].URLs, DeepEquals, []string{"ssh://git@github.com/kostyay/go-git.git"})
c.Assert(cfg.Submodules, HasLen, 1)
c.Assert(cfg.Submodules["qux"].Name, Equals, "qux")
c.Assert(cfg.Submodules["qux"].URL, Equals, "https://github.com/foo/qux.git")
c.Assert(cfg.Submodules["qux"].Branch, Equals, "bar")
c.Assert(cfg.Branches["master"].Remote, Equals, "origin")
c.Assert(cfg.Branches["master"].Merge, Equals, plumbing.ReferenceName("refs/heads/master"))
c.Assert(cfg.Init.DefaultBranch, Equals, "main")
}

func (s *ConfigSuite) TestMarshal(c *C) {
@@ -90,6 +99,8 @@ func (s *ConfigSuite) TestMarshal(c *C) {
url = git@github.com:src-d/go-git.git
fetch = +refs/heads/*:refs/remotes/origin/*
fetch = +refs/pull/*:refs/remotes/origin/pull/*
[remote "insteadOf"]
url = https://github.com/kostyay/go-git.git
[remote "origin"]
url = git@github.com:mcuadros/go-git.git
[remote "win-local"]
@@ -99,12 +110,17 @@ func (s *ConfigSuite) TestMarshal(c *C) {
[branch "master"]
remote = origin
merge = refs/heads/master
[url "ssh://git@github.com/"]
insteadOf = https://github.com/
[init]
defaultBranch = main
`)

cfg := NewConfig()
cfg.Core.IsBare = true
cfg.Core.Worktree = "bar"
cfg.Pack.Window = 20
cfg.Init.DefaultBranch = "main"
cfg.Remotes["origin"] = &RemoteConfig{
Name: "origin",
URLs: []string{"git@github.com:mcuadros/go-git.git"},
@@ -121,6 +137,11 @@ func (s *ConfigSuite) TestMarshal(c *C) {
URLs: []string{"X:\\Git\\"},
}

cfg.Remotes["insteadOf"] = &RemoteConfig{
Name: "insteadOf",
URLs: []string{"https://github.com/kostyay/go-git.git"},
}

cfg.Submodules["qux"] = &Submodule{
Name: "qux",
URL: "https://github.com/foo/qux.git",
@@ -132,6 +153,11 @@ func (s *ConfigSuite) TestMarshal(c *C) {
Merge: "refs/heads/master",
}

cfg.URLs["ssh://git@github.com/"] = &URL{
Name: "ssh://git@github.com/",
InsteadOf: "https://github.com/",
}

b, err := cfg.Marshal()
c.Assert(err, IsNil)

@@ -154,6 +180,8 @@ func (s *ConfigSuite) TestUnmarshalMarshal(c *C) {
email = richard@example.co
[pack]
window = 20
[remote "insteadOf"]
url = https://github.com/kostyay/go-git.git
[remote "origin"]
url = git@github.com:mcuadros/go-git.git
fetch = +refs/heads/*:refs/remotes/origin/*
@@ -163,6 +191,8 @@ func (s *ConfigSuite) TestUnmarshalMarshal(c *C) {
[branch "master"]
remote = origin
merge = refs/heads/master
[url "ssh://git@github.com/"]
insteadOf = https://github.com/
`)

cfg := NewConfig()
@@ -315,3 +345,29 @@ func (s *ConfigSuite) TestRemoteConfigDefaultValues(c *C) {
c.Assert(config.Raw, NotNil)
c.Assert(config.Pack.Window, Equals, DefaultPackWindow)
}

func (s *ConfigSuite) TestLoadConfigLocalScope(c *C) {
cfg, err := LoadConfig(LocalScope)
c.Assert(err, NotNil)
c.Assert(cfg, IsNil)
}

func (s *ConfigSuite) TestRemoveUrlOptions(c *C) {
buf := []byte(`
[remote "alt"]
url = git@github.com:mcuadros/go-git.git
url = git@github.com:src-d/go-git.git
fetch = +refs/heads/*:refs/remotes/origin/*
fetch = +refs/pull/*:refs/remotes/origin/pull/*`)

cfg := NewConfig()
err := cfg.Unmarshal(buf)
c.Assert(err, IsNil)
c.Assert(len(cfg.Remotes), Equals, 1)
cfg.Remotes["alt"].URLs = []string{}

buf, err = cfg.Marshal()
if strings.Contains(string(buf), "url") {
c.Fatal("conifg should not contain any url sections")
}
}
Loading