nebius/SWE-rebench-V2-PRs huggingface dataset:
Repository: go-git/go-git
Pull request #1459 (2025-03-13 13:35:36)

Fix tests TestFetchOfMissingObjects and TestFetchWildcardTags
#### TestFetchWildcardTags
When comparing the expected behaviour versus upstream git cli, it became clear that the tests expected all tags to be pulled - without actually setting that. This is a change in behaviour which will be introduced in v6, whereby Fetch is not expected to return all tags by default.

The git commands used for testing were:
```
git clone --no-checkout --bare  https://github.com/git-fixtures/tags.git /tmp/tags
cd /tmp/tags
git fetch origin '+refs/heads/*:refs/remotes/origin/*'
```

Based on the above, the test was amended to actively request for all tags to be returned.
This change has been tagged as breaking to reflect the previously made change that required it.

#### TestFetchOfMissingObjects
The test was failing due to a recently introduced optimisation, which skipped getting a commit if the reference was already known. The challenge with this approach is that it removes go-git's ability to self-heal when the underlying objects are no longer available.


Patch:
diff --git a/remote.go b/remote.go
index deb96518..6f921397 100644
--- a/remote.go
+++ b/remote.go
@@ -821,13 +821,6 @@ func getHavesFromRef(
 		return nil
 	}
 
-	// No need to load the commit if we know the remote already
-	// has this hash.
-	if remoteRefs[h] {
-		haves[h] = true
-		return nil
-	}
-
 	commit, err := object.GetCommit(s, h)
 	if err != nil {
 		if !errors.Is(err, plumbing.ErrObjectNotFound) {


Test patch:
diff --git a/remote_test.go b/remote_test.go
index 08743798..5074184b 100644
--- a/remote_test.go
+++ b/remote_test.go
@@ -125,6 +125,7 @@ func (s *RemoteSuite) TestFetchWildcardTags() {
 		RefSpecs: []config.RefSpec{
 			config.RefSpec("+refs/heads/*:refs/remotes/origin/*"),
 		},
+		Tags: AllTags,
 	}, []*plumbing.Reference{
 		plumbing.NewReferenceFromStrings("refs/remotes/origin/master", "f7b877701fbf855b44c0a9e86f3fdce2c298b07f"),
 		plumbing.NewReferenceFromStrings("refs/tags/annotated-tag", "b742a2a9fa0afcfa9a6fad080980fbc26b007c69"),
@@ -356,7 +357,7 @@ func (s *RemoteSuite) testFetch(r *Remote, o *FetchOptions, expected []*plumbing
 	for _, exp := range expected {
 		r, err := r.s.Reference(exp.Name())
 		s.Require().NoError(err)
-		s.Equal(r.String(), exp.String())
+		s.Equal(exp.String(), r.String())
 	}
 }
Repository: go-git/go-git
Pull request #1474 (2025-03-26 17:30:38)

plumbing: blame simplification
remove unused result parameter and dead code


Patch:
diff --git a/blame.go b/blame.go
index e3cb39ae..b4b4f9dc 100644
--- a/blame.go
+++ b/blame.go
@@ -107,10 +107,7 @@ func Blame(c *object.Commit, path string) (*BlameResult, error) {
 		b.lineToCommit[i] = needsMap[i].Commit
 	}
 
-	lines, err := newLines(finalLines, b.lineToCommit)
-	if err != nil {
-		return nil, err
-	}
+	lines := newLines(finalLines, b.lineToCommit)
 
 	return &BlameResult{
 		Path:  path,
@@ -143,7 +140,7 @@ func newLine(author, authorName, text string, date time.Time, hash plumbing.Hash
 	}
 }
 
-func newLines(contents []string, commits []*object.Commit) ([]*Line, error) {
+func newLines(contents []string, commits []*object.Commit) []*Line {
 	result := make([]*Line, 0, len(contents))
 	for i := range contents {
 		result = append(result, newLine(
@@ -152,7 +149,7 @@ func newLines(contents []string, commits []*object.Commit) ([]*Line, error) {
 		))
 	}
 
-	return result, nil
+	return result
 }
 
 // this struct is internally used by the blame function to hold its


Test patch:
diff --git a/blame_test.go b/blame_test.go
index 36f90b64..cdf62acd 100644
--- a/blame_test.go
+++ b/blame_test.go
@@ -22,24 +22,22 @@ func TestBlameSuite(t *testing.T) {
 
 func (s *BlameSuite) TestNewLines() {
 	h := plumbing.NewHash("ce9f123d790717599aaeb76bc62510de437761be")
-	lines, err := newLines([]string{"foo"}, []*object.Commit{{
+	lines := newLines([]string{"foo"}, []*object.Commit{{
 		Hash:    h,
 		Message: "foo",
 	}})
 
-	s.NoError(err)
 	s.Len(lines, 1)
 	s.Equal("foo", lines[0].Text)
 	s.Equal(h, lines[0].Hash)
 }
 
 func (s *BlameSuite) TestNewLinesWithNewLine() {
-	lines, err := newLines([]string{"foo", ""}, []*object.Commit{
+	lines := newLines([]string{"foo", ""}, []*object.Commit{
 		{Message: "foo"},
 		{Message: "bar"},
 	})
 
-	s.NoError(err)
 	s.Len(lines, 2)
 	s.Equal("foo", lines[0].Text)
 	s.Equal("", lines[1].Text)
Repository: go-git/go-git
Pull request #1489 (2025-04-06 18:06:21)

internal: trace, read trace target from env
This moves the trace initialization to the internal package and makes it opt-in instead of automatic. It also enables tracing on test runs by default.


Patch:
diff --git a/internal/trace/trace.go b/internal/trace/trace.go
new file mode 100644
index 00000000..d8cdbc45
--- /dev/null
+++ b/internal/trace/trace.go
@@ -0,0 +1,29 @@
+package trace
+
+import (
+	"os"
+	"strconv"
+
+	"github.com/go-git/go-git/v6/utils/trace"
+)
+
+// envToTarget maps what environment variables can be used
+// to enable specific trace targets.
+var envToTarget = map[string]trace.Target{
+	"GIT_TRACE":             trace.General,
+	"GIT_TRACE_PACKET":      trace.Packet,
+	"GIT_TRACE_SSH":         trace.SSH,
+	"GIT_TRACE_PERFORMANCE": trace.Performance,
+}
+
+// ReadEnv reads the environment variables and sets the trace targets.
+// This is used to enable tracing in the go-git library.
+func ReadEnv() {
+	var target trace.Target
+	for k, v := range envToTarget {
+		if val, _ := strconv.ParseBool(os.Getenv(k)); val {
+			target |= v
+		}
+	}
+	trace.SetTarget(target)
+}
diff --git a/utils/trace/trace.go b/utils/trace/trace.go
index 201af0e4..4188be28 100644
--- a/utils/trace/trace.go
+++ b/utils/trace/trace.go
@@ -4,35 +4,15 @@ import (
 	"fmt"
 	"log"
 	"os"
-	"strings"
 	"sync/atomic"
 )
 
-func init() {
-	var target Target
-	for k, v := range envToTarget {
-		if strings.EqualFold(os.Getenv(k), "true") {
-			target |= v
-		}
-	}
-	SetTarget(target)
-}
-
 var (
 	// logger is the logger to use for tracing.
 	logger = newLogger()
 
 	// current is the targets that are enabled for tracing.
 	current atomic.Int32
-
-	// envToTarget maps what environment variables can be used
-	// to enable specific trace targets.
-	envToTarget = map[string]Target{
-		"GIT_TRACE":             General,
-		"GIT_TRACE_PACKET":      Packet,
-		"GIT_TRACE_SSH":         SSH,
-		"GIT_TRACE_PERFORMANCE": Performance,
-	}
 )
 
 func newLogger() *log.Logger {


Test patch:
diff --git a/main_test.go b/main_test.go
new file mode 100644
index 00000000..4e891322
--- /dev/null
+++ b/main_test.go
@@ -0,0 +1,14 @@
+package git
+
+import (
+	"testing"
+
+	"github.com/go-git/go-git/v6/internal/trace"
+)
+
+func TestMain(t *testing.M) {
+	// Set the trace targets based on the environment variables.
+	trace.ReadEnv()
+	// Run the tests.
+	t.Run()
+}