mirror of
https://github.com/yarlson/lnk.git
synced 2025-08-30 17:59:47 +02:00
feat: implement comprehensive edge case handling for init command - Make lnk init idempotent and safe with repository protection, idempotent remote handling, comprehensive tests, and updated documentation
This commit is contained in:
@@ -48,7 +48,19 @@ func (l *Lnk) Init() error {
|
||||
return fmt.Errorf("failed to create lnk directory: %w", err)
|
||||
}
|
||||
|
||||
// Initialize Git repository
|
||||
// Check if there's already a Git repository
|
||||
if l.git.IsGitRepository() {
|
||||
// Repository exists, check if it's a lnk repository
|
||||
if l.git.IsLnkRepository() {
|
||||
// It's a lnk repository, init is idempotent - do nothing
|
||||
return nil
|
||||
} else {
|
||||
// It's not a lnk repository, error to prevent data loss
|
||||
return fmt.Errorf("directory %s appears to contain an existing Git repository that is not managed by lnk. Please backup or move the existing repository before initializing lnk", l.repoPath)
|
||||
}
|
||||
}
|
||||
|
||||
// No existing repository, initialize Git repository
|
||||
if err := l.git.Init(); err != nil {
|
||||
return fmt.Errorf("failed to initialize git repository: %w", err)
|
||||
}
|
||||
|
Reference in New Issue
Block a user