| 170 | } |
| 171 | |
| 172 | func (u *updateCmd) updatePortRepo(nameVersion string, visited map[string]bool) error { |
| 173 | // Check for circular dependencies. |
| 174 | if visited[nameVersion] { |
| 175 | return nil // Already processed, skip. |
| 176 | } |
| 177 | visited[nameVersion] = true |
| 178 | |
| 179 | // Read port file. |
| 180 | var port configs.Port |
| 181 | if err := port.Init(u.celer, nameVersion); err != nil { |
| 182 | return fmt.Errorf("failed to init %s -> %w", nameVersion, err) |
| 183 | } |
| 184 | |
| 185 | // Update repos of port's dependencies. |
| 186 | if u.recursive { |
| 187 | for _, nameVersion := range port.MatchedConfig.Dependencies { |
| 188 | if err := u.updatePortRepo(nameVersion, visited); err != nil { |
| 189 | return err |
| 190 | } |
| 191 | } |
| 192 | } |
| 193 | |
| 194 | // No need to update port if it's not git repo or its code doesn't exist. |
| 195 | srcDir := filepath.Join(dirs.WorkspaceDir, "buildtrees", nameVersion, "src") |
| 196 | if !fileio.PathExists(srcDir) { |
| 197 | color.PrintWarning("src dir not found for %s, updating source is skipped", nameVersion) |
| 198 | return nil |
| 199 | } |
| 200 | |
| 201 | // Do not update local git repo for archive repo. |
| 202 | if !strings.HasSuffix(port.Package.Url, ".git") { |
| 203 | color.PrintWarning("%s is not a remote git repo, updating source is skipped", nameVersion) |
| 204 | return nil |
| 205 | } |
| 206 | |
| 207 | // Update port. |
| 208 | if err := git.UpdateRepo(nameVersion, port.Package.Ref, srcDir, u.force); err != nil { |
| 209 | return err |
| 210 | } |
| 211 | |
| 212 | return nil |
| 213 | } |
| 214 | |
| 215 | func (u *updateCmd) completion(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { |
| 216 | var suggestions []string |