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


The following commit(s) were added to refs/heads/master by this push:
     new b85ea11b newt: Warn about unexpected repositories after upgrade
b85ea11b is described below

commit b85ea11b0a28951abdd50f8de2e456a981e6da2d
Author: Szymon Janc <[email protected]>
AuthorDate: Fri Oct 16 10:23:38 2026 +0200

    newt: Warn about unexpected repositories after upgrade
    
    Repositories that were removed from project.yml, or are now ignored,
    stay in repos/ after "newt upgrade" and can confuse users.  After a
    successful upgrade, warn about any directory in repos/ that doesn't
    belong to a repository used by the project:
    
      WARNING: repos/ contains repositories not used by this project: foo
    
    Hidden entries, like repos/.configs, and plain files are skipped.
    
    The check runs once at the end of the upgrade command, after external
    repos referenced from pkg.yml files have been added, so they are not
    reported as unexpected.
    
    Assisted-by: Claude:claude-opus-5-5
---
 newt/cli/project_cmds.go |  2 ++
 newt/project/project.go  | 36 ++++++++++++++++++++++++++++++++++++
 2 files changed, 38 insertions(+)

diff --git a/newt/cli/project_cmds.go b/newt/cli/project_cmds.go
index a14f796b..eb10191e 100644
--- a/newt/cli/project_cmds.go
+++ b/newt/cli/project_cmds.go
@@ -139,6 +139,8 @@ func upgradeRunCmd(cmd *cobra.Command, args []string) {
 
                NewtUsage(nil, err)
        }
+
+       proj.WarnUnexpectedRepos()
 }
 
 func infoRunCmd(cmd *cobra.Command, args []string) {
diff --git a/newt/project/project.go b/newt/project/project.go
index 46c969bf..a5e8336c 100644
--- a/newt/project/project.go
+++ b/newt/project/project.go
@@ -411,6 +411,42 @@ func (proj *Project) UpgradeIf(
        return inst.Upgrade(specifiedRepoList, force, ask)
 }
 
+// Warns about directories in `repos/` that don't belong to any repository
+// used by this project.  These are usually left over from repositories that
+// were removed from the project or are now ignored.  This must be called only
+// after external repos have been added with GetPkgRepos(), otherwise they are
+// reported as unexpected.
+func (proj *Project) WarnUnexpectedRepos() {
+       reposDir := filepath.Join(proj.BasePath, repo.REPOS_DIR)
+
+       entries, err := os.ReadDir(reposDir)
+       if err != nil {
+               if !os.IsNotExist(err) {
+                       util.OneTimeWarning("failed to read %s: %s", reposDir, 
err.Error())
+               }
+               return
+       }
+
+       var unexpected []string
+       for _, e := range entries {
+               name := e.Name()
+
+               // Skip hidden entries (e.g., `.configs`); newt uses them 
internally.
+               if !e.IsDir() || strings.HasPrefix(name, ".") {
+                       continue
+               }
+
+               if _, ok := proj.repos[name]; !ok {
+                       unexpected = append(unexpected, name)
+               }
+       }
+
+       if len(unexpected) > 0 {
+               util.OneTimeWarning("%s/ contains repositories not used by this 
"+
+                       "project: %s", repo.REPOS_DIR, strings.Join(unexpected, 
", "))
+       }
+}
+
 func (proj *Project) InfoIf(predicate func(r *repo.Repo) bool,
        remote bool) error {
 

Reply via email to