Skip to content

Fix issue #9: symbolic link error #14

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 71 additions & 0 deletions cmd/complex_symlink_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
package cmd

import (
"path/filepath"
"testing"

"github.com/chand1012/git2gpt/prompt"
)

func TestComplexSymlinkHandling(t *testing.T) {
// Create a temporary directory for the test
testDir := "/workspace/test_complex_symlink"

// Generate an ignore list
ignoreList := prompt.GenerateIgnoreList(testDir, "", true)

// Process the repository
repo, err := prompt.ProcessGitRepo(testDir, ignoreList)
if err != nil {
t.Fatalf("Error processing repository with symlinks: %v", err)
}

// Verify that the repository was processed successfully
if repo == nil {
t.Fatal("Repository is nil")
}

// Check if the regular files were included
file1Found := false
file2Found := false
for _, file := range repo.Files {
if file.Path == filepath.Join("dir1", "file1.txt") {
file1Found = true
}
if file.Path == filepath.Join("dir2", "file2.txt") {
file2Found = true
}
}

if !file1Found {
t.Fatal("Expected to find dir1/file1.txt in the repository")
}
if !file2Found {
t.Fatal("Expected to find dir2/file2.txt in the repository")
}

// Verify that the symlinks were included
link1Found := false
link2Found := false
for _, file := range repo.Files {
if file.Path == filepath.Join("public", "link1") {
link1Found = true
if file.Contents != "../dir1" {
t.Fatalf("Expected link1 content to be '../dir1', got '%s'", file.Contents)
}
}
if file.Path == filepath.Join("public", "link2.txt") {
link2Found = true
if file.Contents != "../dir2/file2.txt" {
t.Fatalf("Expected link2.txt content to be '../dir2/file2.txt', got '%s'", file.Contents)
}
}
}

if !link1Found {
t.Fatal("Expected to find public/link1 in the repository")
}
if !link2Found {
t.Fatal("Expected to find public/link2.txt in the repository")
}
}
54 changes: 54 additions & 0 deletions cmd/symlink_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package cmd

import (
"path/filepath"
"testing"

"github.com/chand1012/git2gpt/prompt"
)

func TestSymlinkHandling(t *testing.T) {
// Create a temporary directory for the test
testDir := "/workspace/test_symlink"

// Generate an ignore list
ignoreList := prompt.GenerateIgnoreList(testDir, "", true)

// Process the repository
repo, err := prompt.ProcessGitRepo(testDir, ignoreList)
if err != nil {
t.Fatalf("Error processing repository with symlink: %v", err)
}

// Verify that the repository was processed successfully
if repo == nil {
t.Fatal("Repository is nil")
}

// Check if the test.txt file was included
found := false
for _, file := range repo.Files {
if file.Path == filepath.Join("storage", "test.txt") {
found = true
break
}
}

if !found {
t.Fatal("Expected to find storage/test.txt in the repository")
}

// Verify that the symlink was resolved
// The symlink itself should be included as a file
symlinkFound := false
for _, file := range repo.Files {
if file.Path == filepath.Join("public", "storage") {
symlinkFound = true
break
}
}

if !symlinkFound {
t.Fatal("Expected to find public/storage in the repository")
}
}
Loading