Skip to content

Commit 8b0ca86

Browse files
committed
refine tests
1 parent 34bf43b commit 8b0ca86

3 files changed

Lines changed: 24 additions & 31 deletions

File tree

cmd/git/submodule.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,12 @@ var submodulePath string
1616

1717
var submoduleCmd = &cobra.Command{
1818
Use: "submodule",
19+
Short: "Manage git submodules",
20+
Long: `Add git repositories as submodules to the current git repository.`,
21+
}
22+
23+
var submoduleAddCmd = &cobra.Command{
24+
Use: "add <path-or-url>",
1925
Short: "Add git repositories as submodules to the current repo",
2026
Long: `Add git repositories as submodules to the current git repository.
2127
@@ -46,6 +52,9 @@ The current directory must be a git repository.`,
4652
}
4753

4854
func isGitURL(target string) bool {
55+
if strings.HasPrefix(target, ".") || strings.HasPrefix(target, "/") {
56+
return false
57+
}
4958
return strings.HasPrefix(target, "https://") ||
5059
strings.HasPrefix(target, "http://") ||
5160
strings.HasPrefix(target, "git@") ||
@@ -209,7 +218,8 @@ func extractRepoName(url string) string {
209218
}
210219

211220
func init() {
212-
submoduleCmd.Flags().StringVarP(&submodulePath, "name", "n", "", "Custom name/path for the submodule (URL mode only)")
221+
submoduleAddCmd.Flags().StringVarP(&submodulePath, "name", "n", "", "Custom name/path for the submodule (URL mode only)")
213222

223+
submoduleCmd.AddCommand(submoduleAddCmd)
214224
GitCmd.AddCommand(submoduleCmd)
215225
}

internal/task/task_feature.go

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -53,17 +53,6 @@ func (m *Manager) InitTaskStructure() error {
5353
}
5454
}
5555

56-
// Create example-feature.md in tasks/ directory
57-
examplePath := filepath.Join(m.TaskDir, "tasks", "example-issue.md")
58-
if _, err := os.Stat(examplePath); os.IsNotExist(err) {
59-
if err := os.WriteFile(examplePath, []byte(DefaultExampleFeature), 0644); err != nil {
60-
return fmt.Errorf("failed to create example-issue.md: %w", err)
61-
}
62-
created = append(created, "tasks/example-issue.md")
63-
} else {
64-
existing = append(existing, "tasks/example-issue.md")
65-
}
66-
6756
// Print summary
6857
if len(created) > 0 {
6958
m.UI.Success("Created directories and files:")
@@ -188,7 +177,7 @@ func (m *Manager) GetFeaturePath(name string) (string, error) {
188177
name = name + ".md"
189178
}
190179

191-
featurePath := filepath.Join(m.TaskDir, "tasks", "features", name)
180+
featurePath := filepath.Join(m.TaskDir, "tasks", "issues", name)
192181

193182
if _, err := os.Stat(featurePath); os.IsNotExist(err) {
194183
return "", fmt.Errorf("feature file not found: %s", name)

internal/task/task_feature_test.go

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ func TestInitTaskStructure(t *testing.T) {
1818

1919
// Check directories were created
2020
dirs := []string{
21-
"tasks/features",
21+
"tasks/issues",
2222
"tasks/config",
2323
"tasks/analysis",
2424
"tasks/mindstorm",
@@ -32,19 +32,13 @@ func TestInitTaskStructure(t *testing.T) {
3232
t.Errorf("Directory not created: %s", dir)
3333
}
3434
}
35-
36-
// Check example file was created
37-
examplePath := filepath.Join(tempDir, "tasks", "example-feature.md")
38-
if _, err := os.Stat(examplePath); os.IsNotExist(err) {
39-
t.Error("example-feature.md not created")
40-
}
4135
}
4236

4337
func TestInitTaskStructurePreservesExisting(t *testing.T) {
4438
tempDir := t.TempDir()
4539

4640
// Create existing directory
47-
existingDir := filepath.Join(tempDir, "tasks", "features")
41+
existingDir := filepath.Join(tempDir, "tasks", "issues")
4842
os.MkdirAll(existingDir, 0755)
4943
existingFile := filepath.Join(existingDir, "existing.md")
5044
os.WriteFile(existingFile, []byte("existing content"), 0644)
@@ -78,7 +72,7 @@ func TestCreateFeature(t *testing.T) {
7872
t.Fatalf("CreateFeature failed: %v", err)
7973
}
8074

81-
featurePath := filepath.Join(tempDir, "tasks", "features", "my-feature.md")
75+
featurePath := filepath.Join(tempDir, "tasks", "issues", "my-feature.md")
8276
if _, err := os.Stat(featurePath); os.IsNotExist(err) {
8377
t.Error("Feature file not created")
8478
}
@@ -89,7 +83,7 @@ func TestCreateFeature(t *testing.T) {
8983
t.Fatalf("CreateFeature with extension failed: %v", err)
9084
}
9185

92-
anotherPath := filepath.Join(tempDir, "tasks", "features", "another.md")
86+
anotherPath := filepath.Join(tempDir, "tasks", "issues", "another.md")
9387
if _, err := os.Stat(anotherPath); os.IsNotExist(err) {
9488
t.Error("Feature file with extension not created")
9589
}
@@ -107,13 +101,13 @@ func TestCreateFeatureWithSpaces(t *testing.T) {
107101
}
108102

109103
// Check file was created with dashes instead of spaces
110-
featurePath := filepath.Join(tempDir, "tasks", "features", "make-script-issue.md")
104+
featurePath := filepath.Join(tempDir, "tasks", "issues", "make-script-issue.md")
111105
if _, err := os.Stat(featurePath); os.IsNotExist(err) {
112106
t.Error("Feature file with normalized name not created")
113107
}
114108

115109
// Check file with spaces does NOT exist
116-
wrongPath := filepath.Join(tempDir, "tasks", "features", "make script issue.md")
110+
wrongPath := filepath.Join(tempDir, "tasks", "issues", "make script issue.md")
117111
if _, err := os.Stat(wrongPath); !os.IsNotExist(err) {
118112
t.Error("Feature file with spaces should not exist")
119113
}
@@ -130,7 +124,7 @@ func TestCreateFeatureWithContent(t *testing.T) {
130124
t.Fatalf("CreateFeature with content failed: %v", err)
131125
}
132126

133-
featurePath := filepath.Join(tempDir, "tasks", "features", "custom-content.md")
127+
featurePath := filepath.Join(tempDir, "tasks", "issues", "custom-content.md")
134128
content, err := os.ReadFile(featurePath)
135129
if err != nil {
136130
t.Fatalf("Failed to read feature file: %v", err)
@@ -159,7 +153,7 @@ func TestCreateFeatureWithUnderscores(t *testing.T) {
159153
}
160154

161155
// Check file was created with dashes instead of underscores
162-
featurePath := filepath.Join(tempDir, "tasks", "features", "my-feature-name.md")
156+
featurePath := filepath.Join(tempDir, "tasks", "issues", "my-feature-name.md")
163157
if _, err := os.Stat(featurePath); os.IsNotExist(err) {
164158
t.Error("Feature file with dashes (normalized from underscores) not created")
165159
}
@@ -242,7 +236,7 @@ func TestDeleteFeature(t *testing.T) {
242236
mgr.CreateFeature("to-delete", "")
243237

244238
// Verify it exists
245-
featurePath := filepath.Join(tempDir, "tasks", "features", "to-delete.md")
239+
featurePath := filepath.Join(tempDir, "tasks", "issues", "to-delete.md")
246240
if _, err := os.Stat(featurePath); os.IsNotExist(err) {
247241
t.Fatal("Feature file not created for deletion test")
248242
}
@@ -274,7 +268,7 @@ func TestDeleteFeatureWithSpaces(t *testing.T) {
274268
}
275269

276270
// Verify it's gone
277-
featurePath := filepath.Join(tempDir, "tasks", "features", "delete-me.md")
271+
featurePath := filepath.Join(tempDir, "tasks", "issues", "delete-me.md")
278272
if _, err := os.Stat(featurePath); !os.IsNotExist(err) {
279273
t.Error("Feature file still exists after deletion with spaces")
280274
}
@@ -302,7 +296,7 @@ func TestGetFeaturePath(t *testing.T) {
302296
if err != nil {
303297
t.Fatalf("GetFeaturePath failed: %v", err)
304298
}
305-
expectedPath := filepath.Join(tempDir, "tasks", "features", "test-feature.md")
299+
expectedPath := filepath.Join(tempDir, "tasks", "issues", "test-feature.md")
306300
if path != expectedPath {
307301
t.Errorf("Path mismatch. Got %s, expected %s", path, expectedPath)
308302
}
@@ -328,7 +322,7 @@ func TestGetFeaturePathWithSpaces(t *testing.T) {
328322
if err != nil {
329323
t.Fatalf("GetFeaturePath with spaces failed: %v", err)
330324
}
331-
expectedPath := filepath.Join(tempDir, "tasks", "features", "my-test-feature.md")
325+
expectedPath := filepath.Join(tempDir, "tasks", "issues", "my-test-feature.md")
332326
if path != expectedPath {
333327
t.Errorf("Path mismatch with spaces. Got %s, expected %s", path, expectedPath)
334328
}

0 commit comments

Comments
 (0)