MCPcopy Create free account
hub / github.com/github/gh-aw / TestEnsureGitAttributesNotInGitRepo

Function TestEnsureGitAttributesNotInGitRepo

pkg/cli/gitattributes_test.go:144–175  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

142}
143
144func TestEnsureGitAttributesNotInGitRepo(t *testing.T) {
145 // Create a temporary directory for testing (not a git repo)
146 tmpDir, err := os.MkdirTemp("", "gh-aw-nogit-test")
147 if err != nil {
148 t.Fatalf("Failed to create temp dir: %v", err)
149 }
150 defer os.RemoveAll(tmpDir)
151
152 // Change to temp directory
153 originalDir, err := os.Getwd()
154 if err != nil {
155 t.Fatalf("Failed to get current directory: %v", err)
156 }
157 defer func() {
158 _ = os.Chdir(originalDir)
159 }()
160
161 if err := os.Chdir(tmpDir); err != nil {
162 t.Fatalf("Failed to change to temp directory: %v", err)
163 }
164
165 // Call ensureGitAttributes in non-git directory
166 _, err = ensureGitAttributes()
167 if err == nil {
168 t.Errorf("Expected error when not in git repository, got nil")
169 }
170
171 // Verify no .gitattributes file was created
172 if _, err := os.Stat(".gitattributes"); !os.IsNotExist(err) {
173 t.Errorf("Expected no .gitattributes file to be created outside git repository")
174 }
175}

Callers

nothing calls this directly

Calls 2

ensureGitAttributesFunction · 0.85
ErrorfMethod · 0.45

Tested by

no test coverage detected