-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathgit_cleanup_and_commit.ps1
More file actions
190 lines (157 loc) · 6.62 KB
/
git_cleanup_and_commit.ps1
File metadata and controls
190 lines (157 loc) · 6.62 KB
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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
#!/usr/bin/env pwsh
# Script de nettoyage et organisation du statut Git après git filter-repo
Write-Host "=== Nettoyage et organisation du statut Git ===" -ForegroundColor Green
# 1. Vérifier le statut Git actuel
Write-Host "\n1. Statut Git actuel:" -ForegroundColor Yellow
git status --porcelain
# 2. Supprimer les fichiers de build et temporaires du suivi Git
Write-Host "\n2. Suppression des fichiers de build du suivi Git..." -ForegroundColor Yellow
# Supprimer tous les fichiers bin/ et obj/ du suivi
git rm -r --cached dotnet/samples/ConsoleSamples/bin/ -f 2>$null
git rm -r --cached dotnet/samples/ConsoleSamples/obj/ -f 2>$null
git rm -r --cached dotnet/src/*/bin/ -f 2>$null
git rm -r --cached dotnet/src/*/obj/ -f 2>$null
git rm -r --cached dotnet/src/*/*/bin/ -f 2>$null
git rm -r --cached dotnet/src/*/*/obj/ -f 2>$null
git rm -r --cached dotnet/tests/*/bin/ -f 2>$null
git rm -r --cached dotnet/tests/*/obj/ -f 2>$null
git rm -r --cached dotnet/notebooks/test-packages/bin/ -f 2>$null
git rm -r --cached dotnet/notebooks/test-packages/obj/ -f 2>$null
# Supprimer les fichiers Python cache
git rm -r --cached python/*/__pycache__/ -f 2>$null
git rm -r --cached python/*/*/__pycache__/ -f 2>$null
# Supprimer les fichiers de couverture et temporaires
git rm --cached .coverage -f 2>$null
# 3. Ajouter les fichiers source appropriés
Write-Host "\n3. Ajout des fichiers source au contrôle de version..." -ForegroundColor Yellow
# Fichiers de configuration du projet
git add .gitignore
git add README.md
git add semantic-fleet.sln
# Fichiers source .NET (déjà suivis)
git add dotnet/src/IntegrationTests/testsettings.json
# Fichiers Python (déjà suivis)
git add model_tester/api_utils.py
git add model_tester/transparent_model_test.py
git add tools/verification/vetting/multi_connector_vetting_test_fixed.py
git add tools/verification/vetting/run_vetting_tests.py
# Ajouter les fichiers de projet .NET s'ils existent
$projectFiles = @(
"dotnet/samples/ConsoleSamples/*.csproj",
"dotnet/src/Connectors/*/*.csproj",
"dotnet/src/IntegrationTests/*.csproj",
"dotnet/src/VisualizerCSharp/*.csproj",
"dotnet/tests/*/*.csproj",
"dotnet/notebooks/test-packages/*.csproj"
)
foreach ($pattern in $projectFiles) {
$files = Get-ChildItem $pattern -ErrorAction SilentlyContinue
foreach ($file in $files) {
git add $file.FullName.Replace((Get-Location).Path + "\", "").Replace("\", "/")
}
}
# Ajouter les fichiers source C# s'ils existent
$sourceFiles = @(
"dotnet/samples/ConsoleSamples/*.cs",
"dotnet/src/Connectors/*/*.cs",
"dotnet/src/Connectors/*/*/*.cs",
"dotnet/src/IntegrationTests/*.cs",
"dotnet/src/VisualizerCSharp/*.cs",
"dotnet/tests/*/*.cs"
)
foreach ($pattern in $sourceFiles) {
$files = Get-ChildItem $pattern -Recurse -ErrorAction SilentlyContinue
foreach ($file in $files) {
git add $file.FullName.Replace((Get-Location).Path + "\", "").Replace("\", "/")
}
}
# Ajouter les fichiers Python source s'ils existent
$pythonFiles = @(
"python/*/*.py",
"python/*/*/*.py",
"python/*/*/*/*.py"
)
foreach ($pattern in $pythonFiles) {
$files = Get-ChildItem $pattern -ErrorAction SilentlyContinue
foreach ($file in $files) {
if ($file.FullName -notmatch "__pycache__") {
git add $file.FullName.Replace((Get-Location).Path + "\", "").Replace("\", "/")
}
}
}
# Ajouter les fichiers de configuration et documentation
$configFiles = @(
"*.md",
"*.txt",
"*.yml",
"*.yaml",
"*.json",
"dotnet/notebooks/config/*.json",
"campaign_tests/data/*",
"data/interoperability_tests/*"
)
foreach ($pattern in $configFiles) {
$files = Get-ChildItem $pattern -Recurse -ErrorAction SilentlyContinue
foreach ($file in $files) {
if ($file.FullName -notmatch "bin|obj|node_modules|__pycache__|coverage") {
git add $file.FullName.Replace((Get-Location).Path + "\", "").Replace("\", "/")
}
}
}
# 4. Vérifier le statut après nettoyage
Write-Host "\n4. Statut Git après nettoyage:" -ForegroundColor Yellow
git status
# 5. Créer les commits organisés
Write-Host "\n5. Création des commits..." -ForegroundColor Yellow
# Commit 1: Configuration du projet
git add .gitignore README.md semantic-fleet.sln
git commit -m "feat: Configuration initiale du projet
- Ajout du fichier .gitignore complet pour .NET et Python
- Ajout du README.md avec description du projet
- Configuration de la solution Visual Studio
Après nettoyage de l'historique Git avec git filter-repo"
# Commit 2: Code source principal
git add dotnet/src/IntegrationTests/testsettings.json
git add model_tester/api_utils.py
git add model_tester/transparent_model_test.py
git add tools/verification/vetting/multi_connector_vetting_test_fixed.py
git add tools/verification/vetting/run_vetting_tests.py
git commit -m "feat: Code source principal et outils de test
- Ajout des utilitaires API et tests de modèles transparents
- Ajout des outils de vérification et validation
- Configuration des tests d'intégration
Fichiers nettoyés et validés après suppression des clés API"
# Commit 3: Fichiers de projet et configuration supplémentaires (s'il y en a)
$hasAdditionalFiles = (git diff --cached --name-only).Count -gt 0
if ($hasAdditionalFiles) {
git commit -m "feat: Fichiers de projet et configuration additionnels
- Ajout des fichiers de projet .NET
- Ajout des fichiers source C# et Python
- Configuration et documentation supplémentaires"
}
# 6. Vérifier l'état final
Write-Host "\n6. État final du dépôt:" -ForegroundColor Yellow
git status
git log --oneline -5
# 7. Pousser vers GitHub
Write-Host "\n7. Poussée vers GitHub..." -ForegroundColor Yellow
try {
# Essayer une poussée normale d'abord
git push origin main
Write-Host "✅ Poussée réussie vers origin/main" -ForegroundColor Green
} catch {
Write-Host "⚠️ Poussée normale échouée, tentative avec --force..." -ForegroundColor Yellow
try {
git push origin main --force
Write-Host "✅ Poussée forcée réussie vers origin/main" -ForegroundColor Green
} catch {
Write-Host "❌ Erreur lors de la poussée: $($_.Exception.Message)" -ForegroundColor Red
Write-Host "Vérifiez la configuration du dépôt distant et les permissions." -ForegroundColor Yellow
}
}
# 8. Vérification finale
Write-Host "\n8. Vérification finale:" -ForegroundColor Yellow
$trackedFiles = (git ls-files).Count
Write-Host "Nombre de fichiers sous contrôle de version: $trackedFiles" -ForegroundColor Cyan
Write-Host "\n=== Nettoyage Git terminé ===" -ForegroundColor Green
Write-Host "Le dépôt est maintenant propre et organisé." -ForegroundColor Cyan