From 04dc1756a397edcf99caffd22a85902973a7c40f Mon Sep 17 00:00:00 2001
From: meilier <xingweizheng@huawei.com>
Date: Wed, 3 Feb 2021 01:05:37 +0800
Subject: [PATCH 09/10] checkAndExpandTag return empty when tag is empty

---
 builder/dockerfile/builder.go      | 2 +-
 builder/dockerfile/builder_test.go | 2 +-
 daemon/import.go                   | 4 +++-
 3 files changed, 5 insertions(+), 3 deletions(-)

diff --git a/builder/dockerfile/builder.go b/builder/dockerfile/builder.go
index f860e60b..42229746 100644
--- a/builder/dockerfile/builder.go
+++ b/builder/dockerfile/builder.go
@@ -637,7 +637,7 @@ func parseOutputTag(output string) string {
 // CheckAndExpandTag checks tag name. If it not include a tag, "latest" will be added.
 func CheckAndExpandTag(tag string) (reference.Named, string, error) {
 	if tag == "" {
-		return nil, "<none>:<none>", nil
+		return nil, "", nil
 	}
 
 	newTag := tag
diff --git a/builder/dockerfile/builder_test.go b/builder/dockerfile/builder_test.go
index f8de41f1..3b7513be 100644
--- a/builder/dockerfile/builder_test.go
+++ b/builder/dockerfile/builder_test.go
@@ -1533,7 +1533,7 @@ func TestCheckAndExpandTag(t *testing.T) {
 		{
 			name:    "test 9",
 			tag:     "",
-			output:  "<none>:<none>",
+			output:  "",
 			wantErr: false,
 		},
 		{
diff --git a/daemon/import.go b/daemon/import.go
index 21ffeaa3..3d7c0d03 100644
--- a/daemon/import.go
+++ b/daemon/import.go
@@ -121,7 +121,9 @@ func (b *Backend) Import(req *pb.ImportRequest, stream pb.Control_ImportServer)
 			return errors.Wrapf(err, "error locating image %q in local storage after import", transports.ImageName(dstRef))
 		}
 		imageID = img.ID
-		img.Names = append(img.Names, reference)
+		if reference != "" {
+			img.Names = append(img.Names, reference)
+		}
 		newNames := util.CopyStringsWithoutSpecificElem(img.Names, tmpName)
 		if err = localStore.SetNames(img.ID, newNames); err != nil {
 			return errors.Wrapf(err, "failed to prune temporary name from image %q", imageID)
-- 
2.27.0

