nebius/SWE-rebench-V2-PRs huggingface dataset:
Repository: imdario/mergo
Pull request #116 (2019-04-25 12:37:52)

override values with nil values when set to do so
Fix proposal for Issue #115 ... this fixes the test, but I am not too sure about the behaviour of overwrite vs overwriteWithEmptyValue in that function. I feel I should use overwriteWithEmptyValue?


Patch:
diff --git a/merge.go b/merge.go
index e19208e..5a37942 100644
--- a/merge.go
+++ b/merge.go
@@ -65,7 +65,6 @@ func deepMerge(dstIn, src reflect.Value, visited map[uintptr]*visit, depth int,
 	typeCheck := config.TypeCheck
 	overwriteWithEmptySrc := config.overwriteWithEmptyValue
 	overwriteSliceWithEmptySrc := config.overwriteSliceWithEmptyValue
-	config.overwriteWithEmptyValue = false
 
 	if !src.IsValid() {
 		return
@@ -160,17 +159,19 @@ func deepMerge(dstIn, src reflect.Value, visited map[uintptr]*visit, depth int,
 			}
 
 			dstElement := dst.MapIndex(key)
-
 			if dstElement.IsValid() {
 				k := dstElement.Interface()
 				dstElement = reflect.ValueOf(k)
 			}
 
-			if isReflectNil(srcElement) {
-				if overwrite || isReflectNil(dstElement) {
-					dst.SetMapIndex(key, srcElement)
+			switch srcElement.Kind() {
+			case reflect.Chan, reflect.Func, reflect.Map, reflect.Interface, reflect.Slice:
+				if isReflectNil(srcElement) {
+					if overwrite || isReflectNil(dstElement) {
+						dst.SetMapIndex(key, srcElement)
+					}
+					continue
 				}
-				continue
 			}
 
 			if !srcElement.CanInterface() {


Test patch:
diff --git a/issue115_test.go b/issue115_test.go
new file mode 100644
index 0000000..cce1172
--- /dev/null
+++ b/issue115_test.go
@@ -0,0 +1,20 @@
+package mergo
+
+import (
+	"testing"
+)
+
+func TestIssue115MergeMapWithNilValueToMapWithOverride(t *testing.T) {
+	p1 := map[string]interface{}{
+		"A": 0, "B": 1, "C": 2,
+	}
+	p2 := map[string]interface{}{
+		"D": nil,
+	}
+	if err := Map(&p1, p2, WithOverride); err != nil {
+		t.Fatalf("Error during the merge: %v", err)
+	}
+	if _, ok := p1["D"]; !ok  {
+		t.Errorf("p1 should contain D: %+v", p1)
+	}
+}
Repository: imdario/mergo
Pull request #170 (2020-10-25 01:33:52)

fix typo in error name
Hi,

I came across a typo while looking at how merge was implemented.


Patch:
diff --git a/map.go b/map.go
index a13a7ee..778583e 100644
--- a/map.go
+++ b/map.go
@@ -142,7 +142,7 @@ func MapWithOverwrite(dst, src interface{}, opts ...func(*Config)) error {
 
 func _map(dst, src interface{}, opts ...func(*Config)) error {
 	if dst != nil && reflect.ValueOf(dst).Kind() != reflect.Ptr {
-		return ErrNonPointerAgument
+		return ErrNonPointerArgument
 	}
 	var (
 		vDst, vSrc reflect.Value
diff --git a/merge.go b/merge.go
index afa84a1..5c8e775 100644
--- a/merge.go
+++ b/merge.go
@@ -339,7 +339,7 @@ func WithSliceDeepCopy(config *Config) {
 
 func merge(dst, src interface{}, opts ...func(*Config)) error {
 	if dst != nil && reflect.ValueOf(dst).Kind() != reflect.Ptr {
-		return ErrNonPointerAgument
+		return ErrNonPointerArgument
 	}
 	var (
 		vDst, vSrc reflect.Value
diff --git a/mergo.go b/mergo.go
index 3cc926c..46a9b04 100644
--- a/mergo.go
+++ b/mergo.go
@@ -20,7 +20,7 @@ var (
 	ErrNotSupported                = errors.New("only structs and maps are supported")
 	ErrExpectedMapAsDestination    = errors.New("dst was expected to be a map")
 	ErrExpectedStructAsDestination = errors.New("dst was expected to be a struct")
-	ErrNonPointerAgument           = errors.New("dst must be a pointer")
+	ErrNonPointerArgument          = errors.New("dst must be a pointer")
 )
 
 // During deepMerge, must keep track of checks that are


Test patch:
diff --git a/merge_test.go b/merge_test.go
index dd51dab..bb2c1a4 100644
--- a/merge_test.go
+++ b/merge_test.go
@@ -64,7 +64,7 @@ func TestMergeNonPointer(t *testing.T) {
 			"a": "1",
 		},
 	}
-	want := mergo.ErrNonPointerAgument
+	want := mergo.ErrNonPointerArgument
 
 	if got := mergo.Merge(dst, src); got != want {
 		t.Errorf("want: %s, got: %s", want, got)
@@ -81,7 +81,7 @@ func TestMapNonPointer(t *testing.T) {
 			},
 		},
 	}
-	want := mergo.ErrNonPointerAgument
+	want := mergo.ErrNonPointerArgument
 	if got := mergo.Merge(dst, src); got != want {
 		t.Errorf("want: %s, got: %s", want, got)
 	}
Repository: imdario/mergo
Pull request #175 (2021-01-27 17:10:47)

Fix panic that occurs when a struct has a blank field
This PR fixes https://github.com/imdario/mergo/issues/174.


Patch:
diff --git a/merge.go b/merge.go
index afa84a1..3f13275 100644
--- a/merge.go
+++ b/merge.go
@@ -95,7 +95,7 @@ func deepMerge(dst, src reflect.Value, visited map[uintptr]*visit, depth int, co
 				}
 			}
 		} else {
-			if (isReflectNil(dst) || overwrite) && (!isEmptyValue(src) || overwriteWithEmptySrc) {
+			if dst.CanSet() && (isReflectNil(dst) || overwrite) && (!isEmptyValue(src) || overwriteWithEmptySrc) {
 				dst.Set(src)
 			}
 		}


Test patch:
diff --git a/issue174_test.go b/issue174_test.go
new file mode 100644
index 0000000..d06b68b
--- /dev/null
+++ b/issue174_test.go
@@ -0,0 +1,21 @@
+package mergo_test
+
+import (
+	"testing"
+
+	"github.com/imdario/mergo"
+)
+
+type structWithBlankField struct {
+	_ struct{}
+	A struct{}
+}
+
+func TestIssue174(t *testing.T) {
+	dst := structWithBlankField{}
+	src := structWithBlankField{}
+
+	if err := mergo.Merge(&dst, src, mergo.WithOverride); err != nil {
+		t.Error(err)
+	}
+}
Repository: imdario/mergo
Pull request #212 (2022-05-25 19:44:20)

Upgrade yaml to v3
As requested in "Update the yaml dependency to v3? #206".



Patch:
diff --git a/README.md b/README.md
index fee77ac..ab49fd7 100644
--- a/README.md
+++ b/README.md
@@ -170,7 +170,7 @@ func main() {
 
 Note: if test are failing due missing package, please execute:
 
-    go get gopkg.in/yaml.v2
+    go get gopkg.in/yaml.v3
 
 ### Transformers
 
diff --git a/go.mod b/go.mod
index 3d689d9..6f476d6 100644
--- a/go.mod
+++ b/go.mod
@@ -2,4 +2,4 @@ module github.com/imdario/mergo
 
 go 1.13
 
-require gopkg.in/yaml.v2 v2.3.0
+require gopkg.in/yaml.v3 v3.0.0
diff --git a/go.sum b/go.sum
index 168980d..223abcb 100644
--- a/go.sum
+++ b/go.sum
@@ -1,4 +1,4 @@
 gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
 gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
-gopkg.in/yaml.v2 v2.3.0 h1:clyUAQHOM3G0M3f5vQj7LuJrETvjVot3Z5el9nffUtU=
-gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
+gopkg.in/yaml.v3 v3.0.0 h1:hjy8E9ON/egN1tAYqKb61G10WtihqetD4sz2H+8nIeA=
+gopkg.in/yaml.v3 v3.0.0/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=


Test patch:
diff --git a/mergo_test.go b/mergo_test.go
index 1259ec2..6b3eba7 100644
--- a/mergo_test.go
+++ b/mergo_test.go
@@ -13,7 +13,7 @@ import (
 	"time"
 
 	"github.com/imdario/mergo"
-	"gopkg.in/yaml.v2"
+	"gopkg.in/yaml.v3"
 )
 
 type simpleTest struct {
@@ -603,18 +603,18 @@ func TestMapsWithNilPointer(t *testing.T) {
 func TestYAMLMaps(t *testing.T) {
 	thing := loadYAML("testdata/thing.yml")
 	license := loadYAML("testdata/license.yml")
-	ft := thing["fields"].(map[interface{}]interface{})
-	fl := license["fields"].(map[interface{}]interface{})
+	ft := thing["fields"].(map[string]interface{})
+	fl := license["fields"].(map[string]interface{})
 	// license has one extra field (site) and another already existing in thing (author) that Mergo won't override.
 	expectedLength := len(ft) + len(fl) - 1
 	if err := mergo.Merge(&license, thing); err != nil {
 		t.Error(err.Error())
 	}
-	currentLength := len(license["fields"].(map[interface{}]interface{}))
+	currentLength := len(license["fields"].(map[string]interface{}))
 	if currentLength != expectedLength {
 		t.Errorf(`thing not merged in license properly, license must have %d elements instead of %d`, expectedLength, currentLength)
 	}
-	fields := license["fields"].(map[interface{}]interface{})
+	fields := license["fields"].(map[string]interface{})
 	if _, ok := fields["id"]; !ok {
 		t.Errorf(`thing not merged in license properly, license must have a new id field from thing`)
 	}