1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
//! Clone command implementation for Node.js bindings.
//!
//! # What
//!
//! This module implements the `clone` NAPI function that clones a Git repository
//! and optionally initializes it as a workspace. It handles SSH authentication
//! and workspace configuration in a single operation.
//!
//! # How
//!
//! The function:
//! 1. Validates the input parameters (root path, URL, destination)
//! 2. Calls `execute_clone` from `sublime_cli_tools`
//! 3. Captures the JSON output containing clone operation results
//! 4. Returns a `JsonResponse<CloneData>` with repository information
//!
//! # Why
//!
//! The clone command streamlines the process of setting up new workspace projects:
//! - Clones from any Git URL (HTTPS or SSH)
//! - Handles SSH key authentication
//! - Optionally initializes workspace configuration
//! - Supports shallow clones for faster operations
//!
//! # Examples
//!
//! ```typescript
//! import { clone } from '@websublime/workspace-tools';
//!
//! // Clone a public repository
//! const result = await clone({
//! root: '.',
//! url: 'https://github.com/org/repo.git',
//! destination: 'my-project'
//! });
//!
//! if (result.success) {
//! console.log(`Cloned to: ${result.data.path}`);
//! console.log(`Branch: ${result.data.branch}`);
//! }
//!
//! // Clone with SSH and initialize workspace
//! const sshResult = await clone({
//! root: '.',
//! url: 'git@github.com:org/private-repo.git',
//! destination: 'my-private-project',
//! initialize: true,
//! strategy: 'independent'
//! });
//!
//! if (sshResult.success) {
//! console.log(`Cloned to: ${sshResult.data.path}`);
//! if (sshResult.data.initialized) {
//! console.log(`Config created at: ${sshResult.data.configPath}`);
//! }
//! }
//!
//! // Shallow clone with custom SSH keys
//! const shallowResult = await clone({
//! root: '.',
//! url: 'git@github.com:org/repo.git',
//! destination: 'shallow-clone',
//! depth: 1,
//! branch: 'main',
//! sshKeyPaths: ['~/.ssh/id_ed25519', '~/.ssh/id_rsa']
//! });
//! ```
// TODO: will be implemented on story 9.3 - Clone Command
//
// Implementation outline:
//
// #[napi]
// pub async fn clone(params: CloneParams) -> JsonResponse<CloneData> {
// // 1. Validate parameters
// if let Err(e) = validate_root(¶ms.root) {
// return JsonResponse::from_error_info(e);
// }
//
// // 2. Validate URL is not empty
// if params.url.trim().is_empty() {
// return JsonResponse::validation_error("url cannot be empty", Some("url"));
// }
//
// // 3. Create CloneArgs from params
// let args = CloneArgs {
// url: params.url.clone(),
// destination: params.destination.clone(),
// branch: params.branch.clone(),
// depth: params.depth,
// init: params.initialize.unwrap_or(false),
// strategy: params.strategy.clone(),
// ssh_key_paths: params.ssh_key_paths.clone(),
// ..Default::default()
// };
//
// // 4. Create Output with JSON format for capturing
// let mut buffer = Vec::new();
// let output = Output::new(OutputFormat::Json, &mut buffer, false);
//
// // 5. Determine base path
// let root_path = Path::new(¶ms.root);
// let config_path = None; // Will use default config discovery
//
// // 6. Call execute_clone from CLI (commands/clone.rs)
// match execute_clone(&args, &output, root_path, config_path).await {
// Ok(()) => {
// // 7. Parse JSON response from buffer
// let json_str = String::from_utf8_lossy(&buffer);
// match serde_json::from_str::<JsonResponse<CloneData>>(&json_str) {
// Ok(response) => response,
// Err(e) => JsonResponse::error(format!("Failed to parse clone response: {}", e)),
// }
// }
// Err(e) => JsonResponse::error(format!("Clone failed: {}", e)),
// }
// }
//
// Note: The clone command uses sublime_git_tools::Repo::clone_with_options
// for the underlying git operation. SSH authentication is handled by
// providing custom SSH key paths that are tried in order.
//
// When initialize is true, the init command is automatically called
// after a successful clone to set up the workspace configuration.