Skip to content

Conversation

qiniu-ci
Copy link
Collaborator

@qiniu-ci qiniu-ci commented Aug 24, 2025

🚀 容器内无法使用git

Closes #321 | Auto-generated by CodeAgent 🤖

🎯 Summary

Successfully implemented the git clone approach to replace git worktree for container compatibility. Here's what was...

Key Implementation Points:

  • Successfully implemented the git clone approach to replace git worktree for container compatibility. Here's what was accomplished:
  • ListWorktrees: Updated to scan directory structure instead of using git worktree list
  • RestoreWorktrees: Enhanced to handle both new and old workspace directory formats
  • cleanupWorkspaceWithWorktree: Updated to use directory removal instead of worktree cleanup
  • Removed parseWorktreeList, handleExistingWorktree, and forceRemoveDirectory methods that were specific to git worktree operations
  • Main repository serves as template: Updated regularly and used as source for cloning
🤖 Full AI Analysis
## Summary

Successfully implemented the git clone approach to replace git worktree for container compatibility. Here's what was accomplished:

## Key Changes Made

### 1. **RepoManager Updates** (`internal/workspace/repo_manager.go`)
- **`CreateWorktreeWithName`**: Replaced `git worktree add` with `git clone` from local template repository
- **`RemoveWorktreeWithAI`**: Replaced `git worktree remove` with direct directory removal using `os.RemoveAll`
- **`ListWorktrees`**: Updated to scan directory structure instead of using `git worktree list`
- **`RestoreWorktrees`**: Enhanced to handle both new and old workspace directory formats

### 2. **Manager Updates** (`internal/workspace/manager.go`) 
- **`MoveIssueToPR`**: Replaced `git worktree move` with `os.Rename` for directory renaming
- **`cleanupWorkspaceWithWorktree`**: Updated to use directory removal instead of worktree cleanup

### 3. **Removed Unused Functions**
- Removed `parseWorktreeList`, `handleExistingWorktree`, and `forceRemoveDirectory` methods that were specific to git worktree operations

## Benefits of New Approach

1. **Container Compatibility**: Each workspace now has a complete `.git` directory, eliminating the container mount issues
2. **Network Efficiency**: Still clones from local template repository, saving network bandwidth  
3. **Code Completeness**: Each workspace gets full repository history and can operate independently
4. **Backward Compatibility**: Maintains support for existing directory naming formats

## Implementation Details

- **Main repository serves as template**: Updated regularly and used as source for cloning
- **Independent workspaces**: Each has complete git repository that works inside containers
- **Proper branch management**: Handles both new branch creation and existing branch checkout
- **Comprehensive cleanup**: Directory removal with fallback handling

## Validation

✅ All existing tests pass  
✅ Code properly formatted with `go fmt`  
✅ No breaking changes to... [truncated]

This pull request was automatically generated by CodeAgent on 2025-08-24 22:18:31.

💡 Review Tips:

  • Focus on code quality and correctness
  • Verify the implementation matches the issue requirements
  • Check for proper error handling and edge cases
  • Ensure tests are comprehensive

@qiniu-ci
Copy link
Collaborator Author

qiniu-ci commented Aug 24, 2025

✅ CodeAgent completed successfully!

✅ 🤖 Generate code implementation (369.3s)
✅ 💾 Commit and push changes (19.2s)
✅ 📝 Update PR description (1.0s)

Branch

codeagent/claude/issue-321-1756044719

Pull Request

View Pull Request


Completed in 0.0s

The git worktree approach created workspaces that referenced the parent
repository's .git directory via gitdir files. When these workspaces were
mounted to containers, git commands failed because the parent .git
directory was not available in the container.

Replaced git worktree with git clone approach:
- Each workspace now has a complete, independent .git directory
- Clones from local template repository to maintain network efficiency
- Workspaces can operate fully within containers
- Maintains backward compatibility with existing directory formats
- Updated cleanup logic to use directory removal instead of worktree removal

Changes include:
- CreateWorktreeWithName: git worktree add → git clone + branch checkout
- RemoveWorktreeWithAI: git worktree remove → os.RemoveAll
- ListWorktrees: git worktree list → directory scanning
- MoveIssueToPR: git worktree move → os.Rename
- Enhanced RestoreWorktrees for format compatibility

Closes #321
@@ -178,24 +178,34 @@ func (m *Manager) cleanupWorkspaceWithWorktree(ws *models.Workspace) bool {

if repoManager == nil {
log.Warnf("Repo manager not found for %s", orgRepoPath)
// 即使没有 repoManager,也要尝试删除 session 目录
// 即使没有 repoManager,也要尝试删除工作空间和 session 目录
workspaceRemoved := false
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@claude 帮我分析下,这里是否有问题?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

容器内无法使用git
2 participants