@@ -79,6 +79,88 @@ func TestGetCurrentBranchNotInRepo(t *testing.T) {
7979 assert .Error (t , err , "getCurrentBranch should return an error when not in a git repository" )
8080}
8181
82+ func TestCheckCleanWorkingDirectoryIgnoring (t * testing.T ) {
83+ tmpDir := testutil .TempDir (t , "test-*" )
84+
85+ originalDir , err := os .Getwd ()
86+ require .NoError (t , err )
87+ defer func () {
88+ require .NoError (t , os .Chdir (originalDir ))
89+ }()
90+
91+ require .NoError (t , os .Chdir (tmpDir ))
92+ require .NoError (t , exec .Command ("git" , "init" ).Run ())
93+ require .NoError (t , exec .Command ("git" , "config" , "user.name" , "Test User" ).Run ())
94+ require .NoError (t , exec .Command ("git" , "config" , "user.email" , "test@example.com" ).Run ())
95+
96+ generatedFile := filepath .Join (".github" , "skills" , "agentic-workflows" , "SKILL.md" )
97+ require .NoError (t , os .MkdirAll (filepath .Dir (generatedFile ), 0755 ))
98+ require .NoError (t , os .WriteFile (generatedFile , []byte ("generated" ), 0644 ))
99+
100+ require .NoError (t , checkCleanWorkingDirectoryIgnoring (false , []string {generatedFile }))
101+ require .ErrorContains (t , checkCleanWorkingDirectory (false ), "working directory has uncommitted changes" )
102+
103+ // Staged (but not committed) init file should also be excluded.
104+ require .NoError (t , exec .Command ("git" , "add" , generatedFile ).Run ())
105+ require .NoError (t , checkCleanWorkingDirectoryIgnoring (false , []string {generatedFile }))
106+ require .ErrorContains (t , checkCleanWorkingDirectory (false ), "working directory has uncommitted changes" )
107+
108+ require .NoError (t , exec .Command ("git" , "commit" , "-m" , "initial commit" ).Run ())
109+ require .NoError (t , os .WriteFile (generatedFile , []byte ("updated" ), 0644 ))
110+
111+ require .NoError (t , checkCleanWorkingDirectoryIgnoring (false , []string {generatedFile }))
112+ require .ErrorContains (t , checkCleanWorkingDirectory (false ), "working directory has uncommitted changes" )
113+
114+ require .NoError (t , os .WriteFile ("README.md" , []byte ("user file" ), 0644 ))
115+ require .ErrorContains (
116+ t ,
117+ checkCleanWorkingDirectoryIgnoring (false , []string {generatedFile }),
118+ "working directory has uncommitted changes" ,
119+ )
120+ }
121+
122+ // TestCheckCleanWorkingDirectoryIgnoringAbsolutePaths verifies that absolute
123+ // paths are accepted when the current directory is a subdirectory of the repo.
124+ // This is the case when the wizard is invoked from a nested directory and
125+ // ensureAddRepositoryInitializedWithDetails returns absolute paths.
126+ func TestCheckCleanWorkingDirectoryIgnoringAbsolutePaths (t * testing.T ) {
127+ repoDir := testutil .TempDir (t , "test-*" )
128+
129+ originalDir , err := os .Getwd ()
130+ require .NoError (t , err )
131+ defer func () {
132+ require .NoError (t , os .Chdir (originalDir ))
133+ }()
134+
135+ require .NoError (t , os .Chdir (repoDir ))
136+ require .NoError (t , exec .Command ("git" , "init" ).Run ())
137+ require .NoError (t , exec .Command ("git" , "config" , "user.name" , "Test User" ).Run ())
138+ require .NoError (t , exec .Command ("git" , "config" , "user.email" , "test@example.com" ).Run ())
139+
140+ // Create the init file at the repo root.
141+ generatedFile := filepath .Join (".github" , "skills" , "agentic-workflows" , "SKILL.md" )
142+ require .NoError (t , os .MkdirAll (filepath .Dir (generatedFile ), 0755 ))
143+ require .NoError (t , os .WriteFile (generatedFile , []byte ("generated" ), 0644 ))
144+ absGenerated := filepath .Join (repoDir , generatedFile )
145+
146+ // Create a subdirectory and cd into it to simulate a nested invocation.
147+ subDir := filepath .Join (repoDir , "subdir" )
148+ require .NoError (t , os .MkdirAll (subDir , 0755 ))
149+ require .NoError (t , os .Chdir (subDir ))
150+
151+ // Passing the absolute path from a nested CWD should still exclude the file.
152+ require .NoError (t , checkCleanWorkingDirectoryIgnoring (false , []string {absGenerated }))
153+ require .ErrorContains (t , checkCleanWorkingDirectory (false ), "working directory has uncommitted changes" )
154+
155+ // An unrelated untracked file must still be detected even when the init file is excluded.
156+ require .NoError (t , os .WriteFile (filepath .Join (repoDir , "README.md" ), []byte ("user file" ), 0644 ))
157+ require .ErrorContains (
158+ t ,
159+ checkCleanWorkingDirectoryIgnoring (false , []string {absGenerated }),
160+ "working directory has uncommitted changes" ,
161+ )
162+ }
163+
82164func TestCreateAndSwitchBranch (t * testing.T ) {
83165 tmpDir := testutil .TempDir (t , "test-*" )
84166
0 commit comments