@@ -103,6 +103,11 @@ func TestUpgradeCommand(t *testing.T) {
103103 t .Fatalf ("Failed to write config file: %v" , err )
104104 }
105105
106+ // Create git repo in temp dir
107+ if err := testutils .TestGitInit (testProjectsDir ); err != nil {
108+ t .Fatalf ("Failed init git repo: %v" , err )
109+ }
110+
106111 // Create mock template info getter
107112 mockTemplateInfoGetter := & MockTemplateInfoGetter {
108113 projectName : "template-upgrade-test" ,
@@ -137,6 +142,11 @@ func TestUpgradeCommand(t *testing.T) {
137142
138143 // Test upgrade command with version flag
139144 t .Run ("Upgrade command with version" , func (t * testing.T ) {
145+ // Discard changes between runs
146+ if err := testutils .TestGitDiscardChanges (testProjectsDir ); err != nil {
147+ t .Fatalf ("Failed to clean working tree: %v" , err )
148+ }
149+
140150 // Create a flag set and context with no-op logger
141151 set := flag .NewFlagSet ("test" , 0 )
142152 set .String ("version" , "v0.0.4" , "" )
@@ -186,6 +196,11 @@ func TestUpgradeCommand(t *testing.T) {
186196
187197 // Test upgrade command without version flag
188198 t .Run ("Upgrade command without version" , func (t * testing.T ) {
199+ // Discard changes between runs
200+ if err := testutils .TestGitDiscardChanges (testProjectsDir ); err != nil {
201+ t .Fatalf ("Failed to clean working tree: %v" , err )
202+ }
203+
189204 // Create a flag set and context without version flag, with no-op logger
190205 set := flag .NewFlagSet ("test" , 0 )
191206
@@ -233,6 +248,11 @@ func TestUpgradeCommand(t *testing.T) {
233248
234249 // Test upgrade command with incompatible to devkit version
235250 t .Run ("Upgrade command with incompatible version" , func (t * testing.T ) {
251+ // Discard changes between runs
252+ if err := testutils .TestGitDiscardChanges (testProjectsDir ); err != nil {
253+ t .Fatalf ("Failed to clean working tree: %v" , err )
254+ }
255+
236256 // Create a flag set and context with no-op logger
237257 set := flag .NewFlagSet ("test" , 0 )
238258 set .String ("version" , "v0.0.5" , "" )
@@ -258,6 +278,11 @@ func TestUpgradeCommand(t *testing.T) {
258278
259279 // Test with missing config file
260280 t .Run ("No config file" , func (t * testing.T ) {
281+ // Discard changes between runs
282+ if err := testutils .TestGitDiscardChanges (testProjectsDir ); err != nil {
283+ t .Fatalf ("Failed to clean working tree: %v" , err )
284+ }
285+
261286 // Create a separate directory without a config file
262287 noConfigDir := filepath .Join (testProjectsDir , "no-config" )
263288 err = os .MkdirAll (noConfigDir , 0755 )
0 commit comments