This is an automated email from the ASF dual-hosted git repository.

sjanc pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-newt.git

commit 729d3e45255988060820f065273ef349d61cf2ee
Author: Szymon Janc <[email protected]>
AuthorDate: Mon Oct 19 17:50:18 2026 +0200

    newt/cli: Fix panic in pkg copy/move with unknown source repo
    
    "newt pkg copy @nosuch/foo apps/bar" (and "pkg move") passed a nil repo
    returned by FindRepo to ResolvePackage, causing a nil pointer
    dereference. Report that the source repo does not exist instead, as is
    already done for the destination repo.
    
    Assisted-by: Claude:claude-opus-5-5
---
 newt/cli/pkg_cmds.go    |  4 ++++
 newt/cli_errors_test.go | 10 ++++++++++
 2 files changed, 14 insertions(+)

diff --git a/newt/cli/pkg_cmds.go b/newt/cli/pkg_cmds.go
index 38248f9f..da7b3740 100644
--- a/newt/cli/pkg_cmds.go
+++ b/newt/cli/pkg_cmds.go
@@ -100,6 +100,10 @@ func pkgCloneOrMoveCmd(cmd *cobra.Command, args []string, 
dirOpFn dirOperation,
        srcRepo := proj.LocalRepo()
        if srcRepoName != "" {
                srcRepo = proj.FindRepo(srcRepoName)
+               if srcRepo == nil {
+                       NewtUsage(cmd, util.NewNewtError("Source repo "+
+                               srcRepoName+" does not exist"))
+               }
        }
 
        srcPkg, err := proj.ResolvePackage(srcRepo, srcName)
diff --git a/newt/cli_errors_test.go b/newt/cli_errors_test.go
index 5b81baf2..2c1553df 100644
--- a/newt/cli_errors_test.go
+++ b/newt/cli_errors_test.go
@@ -52,3 +52,13 @@ func TestCliManNoArgs(t *testing.T) {
        cliErrorCheck(t, projDir, nil, "Exactly one argument required",
                "apropos")
 }
+
+// "newt pkg copy" and "newt pkg move" with an unknown source repo.
+func TestCliPkgUnknownSrcRepo(t *testing.T) {
+       projDir := filepath.Join("testdata", "syscfg_collision")
+
+       for _, op := range []string{"copy", "move"} {
+               cliErrorCheck(t, projDir, nil, "Source repo nosuch does not 
exist",
+                       "pkg", op, "@nosuch/foo", "apps/bar")
+       }
+}

Reply via email to