|
9 | 9 | "log" |
10 | 10 | "path" |
11 | 11 | "path/filepath" |
| 12 | + "sort" |
12 | 13 | ) |
13 | 14 |
|
14 | 15 | // ModuleFinder is a type that |
@@ -36,6 +37,13 @@ func Calculate(finder ModuleFinder, tags git.ModuleTags, config repotools.Config |
36 | 37 | } |
37 | 38 |
|
38 | 39 | modules := make(map[string]*Module) |
| 40 | + var repositoryModuleTombstonePaths []string |
| 41 | + |
| 42 | + for moduleDir := range tags { |
| 43 | + if _, ok := repositoryModules[moduleDir]; !ok { |
| 44 | + repositoryModuleTombstonePaths = append(repositoryModuleTombstonePaths, moduleDir) |
| 45 | + } |
| 46 | + } |
39 | 47 |
|
40 | 48 | for moduleDir := range repositoryModules { |
41 | 49 | moduleFile, err := gomod.LoadModuleFile(filepath.Join(rootDir, moduleDir), nil, true) |
@@ -63,14 +71,25 @@ func Calculate(finder ModuleFinder, tags git.ModuleTags, config repotools.Config |
63 | 71 | log.Fatalf("failed to get git changes: %v", err) |
64 | 72 | } |
65 | 73 |
|
66 | | - hasChanges, err = gomod.IsModuleChanged(moduleDir, repositoryModules[moduleDir], changes) |
| 74 | + subModulePaths := repositoryModules[moduleDir] |
| 75 | + |
| 76 | + ignoredModulePaths := make([]string, 0, len(subModulePaths)+len(repositoryModuleTombstonePaths)) |
| 77 | + ignoredModulePaths = append(ignoredModulePaths, subModulePaths...) |
| 78 | + |
| 79 | + if len(repositoryModuleTombstonePaths) > 0 { |
| 80 | + ignoredModulePaths = append(ignoredModulePaths, repositoryModuleTombstonePaths...) |
| 81 | + // IsModuleChanged expects the provided list of ignored modules paths to be sorted |
| 82 | + sort.Strings(ignoredModulePaths) |
| 83 | + } |
| 84 | + |
| 85 | + hasChanges, err = gomod.IsModuleChanged(moduleDir, ignoredModulePaths, changes) |
67 | 86 | if err != nil { |
68 | 87 | return nil, fmt.Errorf("failed to determine module changes: %w", err) |
69 | 88 | } |
70 | 89 |
|
71 | 90 | if !hasChanges { |
72 | 91 | // Check if any of the submodules have been "carved out" of this module since the last tagged release |
73 | | - for _, subModuleDir := range repositoryModules[moduleDir] { |
| 92 | + for _, subModuleDir := range subModulePaths { |
74 | 93 | if _, ok := tags.Latest(subModuleDir); ok { |
75 | 94 | continue |
76 | 95 | } |
|
0 commit comments