GIT_CLONE - Clonar Repositório Git
O que é este Node?
O GIT_CLONE é o node responsável por clonar repositórios Git de um servidor remoto para o sistema local. Ele executa o comando git clone e permite baixar todo o histórico e arquivos de um repositório.
Por que este Node existe?
Em automações que trabalham com código e versionamento, frequentemente precisamos baixar repositórios. O GIT_CLONE existe para:
- Iniciar Projetos: Baixar código fonte para deploy ou processamento
- Backup: Criar cópias locais de repositórios remotos
- Análise: Obter código para análise, auditoria ou testes
- Sincronização: Manter cópias locais atualizadas de projetos
Como funciona internamente?
Quando o GIT_CLONE é executado, o sistema:
- Recebe parâmetros: URL do repositório e diretório de destino
- Substitui variáveis: Aplica variáveis do contexto aos parâmetros
- Executa clone: Roda
git clone [url] [directory] - Valida resultado: Verifica se o clone foi bem-sucedido
- Se erro: Lança exceção com detalhes do erro
- Se sucesso: Retorna confirmação e output do comando
Código interno (git.executor.ts:104-111):
private async clone(data: any, context: ExecutionContext): Promise<any> {
const { repositoryUrl, targetDirectory } = data;
const replacedUrl = this.replaceVariables(repositoryUrl, context.variables);
const replacedDir = this.replaceVariables(targetDirectory, context.variables);
const { stdout } = await execAsync(`git clone ${replacedUrl} ${replacedDir}`);
return { output: stdout, cloned: true };
}
Quando você DEVE usar este Node?
Use GIT_CLONE sempre que precisar de baixar um repositório Git completo:
Casos de uso
- Deploy automatizado: "Preciso baixar o código da aplicação para fazer deploy"
- Backup de projetos: "Quero fazer backup diário de todos os repositórios da equipe"
- Análise de código: "Preciso baixar o projeto para executar análise de segurança"
- Setup de ambiente: "Novo desenvolvedor entrando, preciso clonar todos os repos necessários"
Quando NÃO usar GIT_CLONE
- Repositório já existe: Use GIT_PULL para atualizar
- Apenas um arquivo: Use API do GitHub/GitLab diretamente
- Sem Git instalado: Impossível executar, precisa de Git no servidor
Parâmetros Detalhados
repositoryUrl (string, obrigatório)
O que é: URL completa do repositório Git a ser clonado. Pode ser HTTPS ou SSH.
Exemplos válidos:
- HTTPS: https://github.com/usuario/projeto.git
- SSH: git@github.com:usuario/projeto.git
- Com token: https://token@github.com/usuario/projeto.git
Flow completo para testar:
{
"name": "Teste Git Clone - Repository URL",
"nodes": [
{
"id": "start_1",
"type": "start",
"position": { "x": 100, "y": 100 },
"data": { "label": "Início" }
},
{
"id": "variable_1",
"type": "variable",
"position": { "x": 300, "y": 100 },
"data": {
"label": "Definir URL",
"parameters": {
"variable": "repo_url",
"value": "https://github.com/torvalds/linux.git"
}
}
},
{
"id": "git_clone_1",
"type": "git",
"position": { "x": 500, "y": 100 },
"data": {
"label": "Clonar Repo",
"operation": "clone",
"repositoryUrl": "{{repo_url}}",
"targetDirectory": "/tmp/linux-clone",
"responseVariable": "clone_result"
}
},
{
"id": "message_1",
"type": "message",
"position": { "x": 700, "y": 100 },
"data": {
"label": "Confirmar",
"parameters": {
"message": "Repositório clonado com sucesso!\nStatus: {{clone_result.cloned}}"
}
}
},
{
"id": "end_1",
"type": "end",
"position": { "x": 900, "y": 100 },
"data": { "label": "Fim" }
}
],
"edges": [
{ "source": "start_1", "target": "variable_1" },
{ "source": "variable_1", "target": "git_clone_1" },
{ "source": "git_clone_1", "target": "message_1" },
{ "source": "message_1", "target": "end_1" }
]
}
Teste: Inicie o flow. O sistema clonará o repositório do Linux kernel. Resposta esperada: confirmação do clone.
targetDirectory (string, obrigatório)
O que é: Caminho completo do diretório onde o repositório será clonado. O diretório NÃO deve existir previamente.
Padrão: Nenhum (obrigatório informar)
Atenção:
- Use paths absolutos: /home/user/projetos/meu-repo
- Diretório será criado automaticamente
- Se já existir, Git retornará erro
Flow completo para testar:
{
"name": "Teste Git Clone - Target Directory",
"nodes": [
{
"id": "start_1",
"type": "start",
"position": { "x": 100, "y": 100 },
"data": { "label": "Início" }
},
{
"id": "input_1",
"type": "input",
"position": { "x": 300, "y": 100 },
"data": {
"label": "Nome do Projeto",
"parameters": {
"message": "Digite o nome do diretório:",
"variable": "dir_name"
}
}
},
{
"id": "git_clone_1",
"type": "git",
"position": { "x": 500, "y": 100 },
"data": {
"label": "Clonar",
"operation": "clone",
"repositoryUrl": "https://github.com/nodejs/node.git",
"targetDirectory": "/tmp/{{dir_name}}",
"responseVariable": "clone_result"
}
},
{
"id": "message_1",
"type": "message",
"position": { "x": 700, "y": 100 },
"data": {
"label": "Resultado",
"parameters": {
"message": "Clonado em: /tmp/{{dir_name}}"
}
}
},
{
"id": "end_1",
"type": "end",
"position": { "x": 900, "y": 100 },
"data": { "label": "Fim" }
}
],
"edges": [
{ "source": "start_1", "target": "input_1" },
{ "source": "input_1", "target": "git_clone_1" },
{ "source": "git_clone_1", "target": "message_1" },
{ "source": "message_1", "target": "end_1" }
]
}
Teste: Digite "node-project" quando solicitado. O sistema clonará Node.js em /tmp/node-project.
repositoryPath (string, obrigatório)
O que é: Herdado da estrutura base do Git. No clone, geralmente não é usado, mas targetDirectory cumpre esse papel.
responseVariable (string, opcional)
O que é: Nome da variável onde o resultado do clone será armazenado.
Padrão: Nenhum (resultado não é armazenado)
Estrutura do retorno:
{
"output": "Cloning into '/tmp/projeto'...\ndone.",
"cloned": true
}
Flow completo para testar:
{
"name": "Teste Git Clone - Response Variable",
"nodes": [
{
"id": "start_1",
"type": "start",
"position": { "x": 100, "y": 100 },
"data": { "label": "Início" }
},
{
"id": "git_clone_1",
"type": "git",
"position": { "x": 300, "y": 100 },
"data": {
"label": "Clonar com Variável",
"operation": "clone",
"repositoryUrl": "https://github.com/microsoft/typescript.git",
"targetDirectory": "/tmp/typescript-test",
"responseVariable": "clone_info"
}
},
{
"id": "condition_1",
"type": "condition",
"position": { "x": 500, "y": 100 },
"data": {
"label": "Verificar Clone",
"parameters": {
"condition": "{{clone_info.cloned}} === true"
}
}
},
{
"id": "message_success",
"type": "message",
"position": { "x": 700, "y": 50 },
"data": {
"label": "Sucesso",
"parameters": {
"message": "Clone bem-sucedido!\n{{clone_info.output}}"
}
}
},
{
"id": "message_error",
"type": "message",
"position": { "x": 700, "y": 150 },
"data": {
"label": "Erro",
"parameters": {
"message": "Falha no clone"
}
}
},
{
"id": "end_1",
"type": "end",
"position": { "x": 900, "y": 100 },
"data": { "label": "Fim" }
}
],
"edges": [
{ "source": "start_1", "target": "git_clone_1" },
{ "source": "git_clone_1", "target": "condition_1" },
{ "source": "condition_1", "target": "message_success", "label": "true" },
{ "source": "condition_1", "target": "message_error", "label": "false" },
{ "source": "message_success", "target": "end_1" },
{ "source": "message_error", "target": "end_1" }
]
}
Teste: Execute o flow. Sistema verifica se clone foi bem-sucedido e mostra mensagem apropriada.
Parâmetros
| Campo | Tipo | Obrigatório | Descrição |
|---|---|---|---|
| operation | string | Sim | Deve ser "clone" |
| repositoryUrl | string | Sim | URL do repositório (HTTPS ou SSH) |
| targetDirectory | string | Sim | Diretório de destino (será criado) |
| responseVariable | string | Não | Variável para armazenar resultado |
Exemplo 1: Clone de Repositório Público
Objetivo: Clonar repositório público do GitHub para análise
JSON para Importar
{
"name": "Clone Repositório Público",
"nodes": [
{
"id": "start_1",
"type": "start",
"position": { "x": 100, "y": 100 },
"data": { "label": "Início" }
},
{
"id": "message_1",
"type": "message",
"position": { "x": 300, "y": 100 },
"data": {
"label": "Aviso Inicial",
"parameters": {
"message": "Iniciando clone do repositório React..."
}
}
},
{
"id": "git_clone_1",
"type": "git",
"position": { "x": 500, "y": 100 },
"data": {
"label": "Clonar React",
"operation": "clone",
"repositoryUrl": "https://github.com/facebook/react.git",
"targetDirectory": "/tmp/react-analysis",
"responseVariable": "clone_result"
}
},
{
"id": "message_2",
"type": "message",
"position": { "x": 700, "y": 100 },
"data": {
"label": "Confirmação",
"parameters": {
"message": "Repositório React clonado com sucesso em /tmp/react-analysis!\nStatus: {{clone_result.cloned}}"
}
}
},
{
"id": "end_1",
"type": "end",
"position": { "x": 900, "y": 100 },
"data": { "label": "Fim" }
}
],
"edges": [
{ "source": "start_1", "target": "message_1" },
{ "source": "message_1", "target": "git_clone_1" },
{ "source": "git_clone_1", "target": "message_2" },
{ "source": "message_2", "target": "end_1" }
]
}
Saída esperada:
Sistema: Iniciando clone do repositório React...
Sistema: Repositório React clonado com sucesso em /tmp/react-analysis!
Status: true
Exemplo 2: Clone com Autenticação (Token)
Objetivo: Clonar repositório privado usando token de acesso
JSON para Importar
{
"name": "Clone Repositório Privado",
"nodes": [
{
"id": "start_1",
"type": "start",
"position": { "x": 100, "y": 100 },
"data": { "label": "Início" }
},
{
"id": "variable_1",
"type": "variable",
"position": { "x": 300, "y": 100 },
"data": {
"label": "Configurar Token",
"parameters": {
"variable": "github_token",
"value": "ghp_SeuTokenAqui123456789"
}
}
},
{
"id": "variable_2",
"type": "variable",
"position": { "x": 500, "y": 100 },
"data": {
"label": "URL Completa",
"parameters": {
"variable": "repo_url",
"value": "https://{{github_token}}@github.com/empresa/projeto-privado.git"
}
}
},
{
"id": "git_clone_1",
"type": "git",
"position": { "x": 700, "y": 100 },
"data": {
"label": "Clonar Privado",
"operation": "clone",
"repositoryUrl": "{{repo_url}}",
"targetDirectory": "/var/www/projeto-privado",
"responseVariable": "clone_result"
}
},
{
"id": "message_1",
"type": "message",
"position": { "x": 900, "y": 100 },
"data": {
"label": "Sucesso",
"parameters": {
"message": "Projeto privado clonado com sucesso!"
}
}
},
{
"id": "end_1",
"type": "end",
"position": { "x": 1100, "y": 100 },
"data": { "label": "Fim" }
}
],
"edges": [
{ "source": "start_1", "target": "variable_1" },
{ "source": "variable_1", "target": "variable_2" },
{ "source": "variable_2", "target": "git_clone_1" },
{ "source": "git_clone_1", "target": "message_1" },
{ "source": "message_1", "target": "end_1" }
]
}
Saída esperada:
Sistema: Projeto privado clonado com sucesso!
Exemplo 3: Clone Múltiplos Repositórios
Objetivo: Clonar vários repositórios em sequência
JSON para Importar
{
"name": "Clone Múltiplos Repositórios",
"nodes": [
{
"id": "start_1",
"type": "start",
"position": { "x": 100, "y": 100 },
"data": { "label": "Início" }
},
{
"id": "message_1",
"type": "message",
"position": { "x": 300, "y": 100 },
"data": {
"label": "Início",
"parameters": {
"message": "Iniciando clone de múltiplos repositórios..."
}
}
},
{
"id": "git_clone_1",
"type": "git",
"position": { "x": 500, "y": 50 },
"data": {
"label": "Clonar Vue",
"operation": "clone",
"repositoryUrl": "https://github.com/vuejs/vue.git",
"targetDirectory": "/tmp/frameworks/vue",
"responseVariable": "clone_vue"
}
},
{
"id": "git_clone_2",
"type": "git",
"position": { "x": 500, "y": 150 },
"data": {
"label": "Clonar Angular",
"operation": "clone",
"repositoryUrl": "https://github.com/angular/angular.git",
"targetDirectory": "/tmp/frameworks/angular",
"responseVariable": "clone_angular"
}
},
{
"id": "git_clone_3",
"type": "git",
"position": { "x": 500, "y": 250 },
"data": {
"label": "Clonar Svelte",
"operation": "clone",
"repositoryUrl": "https://github.com/sveltejs/svelte.git",
"targetDirectory": "/tmp/frameworks/svelte",
"responseVariable": "clone_svelte"
}
},
{
"id": "message_2",
"type": "message",
"position": { "x": 700, "y": 150 },
"data": {
"label": "Resumo",
"parameters": {
"message": "Clones completos:\n✓ Vue: {{clone_vue.cloned}}\n✓ Angular: {{clone_angular.cloned}}\n✓ Svelte: {{clone_svelte.cloned}}"
}
}
},
{
"id": "end_1",
"type": "end",
"position": { "x": 900, "y": 150 },
"data": { "label": "Fim" }
}
],
"edges": [
{ "source": "start_1", "target": "message_1" },
{ "source": "message_1", "target": "git_clone_1" },
{ "source": "git_clone_1", "target": "git_clone_2" },
{ "source": "git_clone_2", "target": "git_clone_3" },
{ "source": "git_clone_3", "target": "message_2" },
{ "source": "message_2", "target": "end_1" }
]
}
Saída esperada:
Sistema: Iniciando clone de múltiplos repositórios...
Sistema: Clones completos:
✓ Vue: true
✓ Angular: true
✓ Svelte: true
Resposta do Node
{
"output": "Cloning into '/tmp/projeto'...\nremote: Enumerating objects: 1000, done.\nremote: Counting objects: 100% (1000/1000), done.\nremote: Compressing objects: 100% (800/800), done.\nReceiving objects: 100% (1000/1000), 5.00 MiB | 2.00 MiB/s, done.\nResolving deltas: 100% (500/500), done.",
"cloned": true
}
Boas Práticas
✅ SIM:
- Use SSH keys para repositórios privados (mais seguro que tokens)
- Valide se o diretório de destino está disponível
- Clone em diretórios temporários para testes
- Use paths absolutos para evitar erros
- Armazene o resultado em variável para validação posterior
- Configure timeout adequado para repos grandes
❌ NÃO:
- Não clone repositórios enormes sem necessidade
- Não hardcode tokens ou senhas na URL
- Não clone em diretórios de sistema (/etc, /usr)
- Não reuse diretórios já existentes
- Não clone sem verificar espaço em disco
- Não exponha credenciais em logs ou mensagens
Dicas
💡 Dica 1: Para repositórios grandes, considere usar shallow clone (git clone --depth 1) via comando customizado
💡 Dica 2: Use variáveis de ambiente para tokens e credenciais sensíveis
💡 Dica 3: Combine com nodes de validação para verificar espaço em disco antes do clone
💡 Dica 4: Para múltiplos clones, use LOOP node com lista de URLs
💡 Dica 5: Após clone, use GIT_STATUS para verificar a integridade do repositório
Próximo Node
→ GIT_PULL - Atualizar repositório já clonado → GIT_STATUS - Verificar status do repositório clonado → GIT_LOG - Ver histórico de commits do repo clonado