Skip to content

Commit b6ee085

Browse files
committed
feat: improve Git installation check implementation
- Add comprehensive unit tests for checkGitInstalled function - Improve error handling specificity to differentiate Git check failures - Refactor promise chains to async/await pattern for better readability - Add JSDoc documentation to exported checkGitInstalled function - Add missing translations for Git warning messages in all locales These improvements enhance code quality, maintainability, and user experience while maintaining backward compatibility with the checkpoint service.
1 parent f5511e9 commit b6ee085

File tree

20 files changed

+132
-31
lines changed

20 files changed

+132
-31
lines changed

src/core/checkpoints/index.ts

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -73,21 +73,24 @@ export function getCheckpointService(cline: Task) {
7373
cline.checkpointServiceInitializing = true
7474

7575
// Check if Git is installed before initializing the service
76-
checkGitInstalled()
77-
.then((gitInstalled) => {
76+
;(async () => {
77+
try {
78+
const gitInstalled = await checkGitInstalled()
79+
7880
if (!gitInstalled) {
7981
log("[Task#getCheckpointService] Git is not installed, disabling checkpoints")
8082
cline.enableCheckpoints = false
8183
cline.checkpointServiceInitializing = false
8284

8385
// Show user-friendly notification
84-
vscode.window
85-
.showWarningMessage(t("common:errors.git_not_installed"), t("common:buttons.learn_more"))
86-
.then((selection) => {
87-
if (selection === t("common:buttons.learn_more")) {
88-
vscode.env.openExternal(vscode.Uri.parse("https://git-scm.com/downloads"))
89-
}
90-
})
86+
const selection = await vscode.window.showWarningMessage(
87+
t("common:errors.git_not_installed"),
88+
t("common:buttons.learn_more"),
89+
)
90+
91+
if (selection === t("common:buttons.learn_more")) {
92+
vscode.env.openExternal(vscode.Uri.parse("https://git-scm.com/downloads"))
93+
}
9194

9295
return
9396
}
@@ -112,13 +115,19 @@ export function getCheckpointService(cline: Task) {
112115
cline.enableCheckpoints = false
113116
}
114117
})
115-
})
116-
.catch((err) => {
117-
log("[Task#getCheckpointService] error checking Git installation, disabling checkpoints")
118-
console.error(err)
118+
} catch (err) {
119+
// Differentiate between Git check errors and other errors
120+
if (err?.message?.includes("git") || err?.message?.includes("Git")) {
121+
log("[Task#getCheckpointService] Git check failed, disabling checkpoints")
122+
console.error("Git check error:", err)
123+
} else {
124+
log("[Task#getCheckpointService] Unexpected error during initialization, disabling checkpoints")
125+
console.error("Initialization error:", err)
126+
}
119127
cline.enableCheckpoints = false
120128
cline.checkpointServiceInitializing = false
121-
})
129+
}
130+
})()
122131

123132
service.on("checkpoint", ({ isFirst, fromHash: from, toHash: to }) => {
124133
try {

src/i18n/locales/ca/common.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
"could_not_open_file_generic": "No s'ha pogut obrir el fitxer!",
3333
"checkpoint_timeout": "S'ha esgotat el temps en intentar restaurar el punt de control.",
3434
"checkpoint_failed": "Ha fallat la restauració del punt de control.",
35+
"git_not_installed": "Git és necessari per a la funció de punts de control. Si us plau, instal·la Git per activar els punts de control.",
3536
"no_workspace": "Si us plau, obre primer una carpeta de projecte",
3637
"update_support_prompt": "Ha fallat l'actualització del missatge de suport",
3738
"reset_support_prompt": "Ha fallat el restabliment del missatge de suport",
@@ -111,7 +112,8 @@
111112
},
112113
"buttons": {
113114
"save": "Desar",
114-
"edit": "Editar"
115+
"edit": "Editar",
116+
"learn_more": "Més informació"
115117
},
116118
"tasks": {
117119
"canceled": "Error de tasca: Ha estat aturada i cancel·lada per l'usuari.",

src/i18n/locales/de/common.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
"could_not_open_file_generic": "Datei konnte nicht geöffnet werden!",
2929
"checkpoint_timeout": "Zeitüberschreitung beim Versuch, den Checkpoint wiederherzustellen.",
3030
"checkpoint_failed": "Fehler beim Wiederherstellen des Checkpoints.",
31+
"git_not_installed": "Git ist für die Checkpoint-Funktion erforderlich. Bitte installiere Git, um Checkpoints zu aktivieren.",
3132
"no_workspace": "Bitte öffne zuerst einen Projektordner",
3233
"update_support_prompt": "Fehler beim Aktualisieren der Support-Nachricht",
3334
"reset_support_prompt": "Fehler beim Zurücksetzen der Support-Nachricht",
@@ -107,7 +108,8 @@
107108
},
108109
"buttons": {
109110
"save": "Speichern",
110-
"edit": "Bearbeiten"
111+
"edit": "Bearbeiten",
112+
"learn_more": "Mehr erfahren"
111113
},
112114
"tasks": {
113115
"canceled": "Aufgabenfehler: Die Aufgabe wurde vom Benutzer gestoppt und abgebrochen.",

src/i18n/locales/es/common.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
"could_not_open_file_generic": "¡No se pudo abrir el archivo!",
2929
"checkpoint_timeout": "Se agotó el tiempo al intentar restaurar el punto de control.",
3030
"checkpoint_failed": "Error al restaurar el punto de control.",
31+
"git_not_installed": "Git es necesario para la función de puntos de control. Por favor, instala Git para activar los puntos de control.",
3132
"no_workspace": "Por favor, abre primero una carpeta de proyecto",
3233
"update_support_prompt": "Error al actualizar el mensaje de soporte",
3334
"reset_support_prompt": "Error al restablecer el mensaje de soporte",
@@ -107,7 +108,8 @@
107108
},
108109
"buttons": {
109110
"save": "Guardar",
110-
"edit": "Editar"
111+
"edit": "Editar",
112+
"learn_more": "Más información"
111113
},
112114
"tasks": {
113115
"canceled": "Error de tarea: Fue detenida y cancelada por el usuario.",

src/i18n/locales/fr/common.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
"could_not_open_file_generic": "Impossible d'ouvrir le fichier !",
2929
"checkpoint_timeout": "Expiration du délai lors de la tentative de rétablissement du checkpoint.",
3030
"checkpoint_failed": "Échec du rétablissement du checkpoint.",
31+
"git_not_installed": "Git est requis pour la fonctionnalité des points de contrôle. Veuillez installer Git pour activer les points de contrôle.",
3132
"no_workspace": "Veuillez d'abord ouvrir un espace de travail",
3233
"update_support_prompt": "Erreur lors de la mise à jour du prompt de support",
3334
"reset_support_prompt": "Erreur lors de la réinitialisation du prompt de support",
@@ -107,7 +108,8 @@
107108
},
108109
"buttons": {
109110
"save": "Enregistrer",
110-
"edit": "Modifier"
111+
"edit": "Modifier",
112+
"learn_more": "En savoir plus"
111113
},
112114
"tasks": {
113115
"canceled": "Erreur de tâche : Elle a été arrêtée et annulée par l'utilisateur.",

src/i18n/locales/hi/common.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
"could_not_open_file_generic": "फ़ाइल नहीं खोली जा सकी!",
2929
"checkpoint_timeout": "चेकपॉइंट को पुनर्स्थापित करने का प्रयास करते समय टाइमआउट हो गया।",
3030
"checkpoint_failed": "चेकपॉइंट पुनर्स्थापित करने में विफल।",
31+
"git_not_installed": "चेकपॉइंट सुविधा के लिए Git आवश्यक है। कृपया चेकपॉइंट সক্ষম करने के लिए Git इंस्टॉल करें।",
3132
"no_workspace": "कृपया पहले प्रोजेक्ट फ़ोल्डर खोलें",
3233
"update_support_prompt": "सपोर्ट प्रॉम्प्ट अपडेट करने में विफल",
3334
"reset_support_prompt": "सपोर्ट प्रॉम्प्ट रीसेट करने में विफल",
@@ -107,7 +108,8 @@
107108
},
108109
"buttons": {
109110
"save": "सहेजें",
110-
"edit": "संपादित करें"
111+
"edit": "संपादित करें",
112+
"learn_more": "और अधिक जानें"
111113
},
112114
"tasks": {
113115
"canceled": "टास्क त्रुटि: इसे उपयोगकर्ता द्वारा रोका और रद्द किया गया था।",

src/i18n/locales/id/common.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
"could_not_open_file_generic": "Tidak dapat membuka file!",
2929
"checkpoint_timeout": "Timeout saat mencoba memulihkan checkpoint.",
3030
"checkpoint_failed": "Gagal memulihkan checkpoint.",
31+
"git_not_installed": "Git diperlukan untuk fitur checkpoint. Silakan instal Git untuk mengaktifkan checkpoint.",
3132
"no_workspace": "Silakan buka folder proyek terlebih dahulu",
3233
"update_support_prompt": "Gagal memperbarui support prompt",
3334
"reset_support_prompt": "Gagal mereset support prompt",
@@ -107,7 +108,8 @@
107108
},
108109
"buttons": {
109110
"save": "Simpan",
110-
"edit": "Edit"
111+
"edit": "Edit",
112+
"learn_more": "Pelajari Lebih Lanjut"
111113
},
112114
"tasks": {
113115
"canceled": "Error tugas: Dihentikan dan dibatalkan oleh pengguna.",

src/i18n/locales/it/common.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
"could_not_open_file_generic": "Impossibile aprire il file!",
2929
"checkpoint_timeout": "Timeout durante il tentativo di ripristinare il checkpoint.",
3030
"checkpoint_failed": "Impossibile ripristinare il checkpoint.",
31+
"git_not_installed": "Git è richiesto per la funzione di checkpoint. Per favore, installa Git per abilitare i checkpoint.",
3132
"no_workspace": "Per favore, apri prima una cartella di progetto",
3233
"update_support_prompt": "Errore durante l'aggiornamento del messaggio di supporto",
3334
"reset_support_prompt": "Errore durante il ripristino del messaggio di supporto",
@@ -107,7 +108,8 @@
107108
},
108109
"buttons": {
109110
"save": "Salva",
110-
"edit": "Modifica"
111+
"edit": "Modifica",
112+
"learn_more": "Scopri di più"
111113
},
112114
"tasks": {
113115
"canceled": "Errore attività: È stata interrotta e annullata dall'utente.",

src/i18n/locales/ja/common.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
"could_not_open_file_generic": "ファイルを開けませんでした!",
2929
"checkpoint_timeout": "チェックポイントの復元を試みる際にタイムアウトしました。",
3030
"checkpoint_failed": "チェックポイントの復元に失敗しました。",
31+
"git_not_installed": "チェックポイント機能にはGitが必要です。チェックポイントを有効にするにはGitをインストールしてください。",
3132
"no_workspace": "まずプロジェクトフォルダを開いてください",
3233
"update_support_prompt": "サポートメッセージの更新に失敗しました",
3334
"reset_support_prompt": "サポートメッセージのリセットに失敗しました",
@@ -107,7 +108,8 @@
107108
},
108109
"buttons": {
109110
"save": "保存",
110-
"edit": "編集"
111+
"edit": "編集",
112+
"learn_more": "詳細"
111113
},
112114
"tasks": {
113115
"canceled": "タスクエラー:ユーザーによって停止およびキャンセルされました。",

src/i18n/locales/ko/common.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
"could_not_open_file_generic": "파일을 열 수 없습니다!",
2929
"checkpoint_timeout": "체크포인트 복원을 시도하는 중 시간 초과되었습니다.",
3030
"checkpoint_failed": "체크포인트 복원에 실패했습니다.",
31+
"git_not_installed": "체크포인트 기능을 사용하려면 Git이 필요합니다. 체크포인트를 활성화하려면 Git을 설치하세요.",
3132
"no_workspace": "먼저 프로젝트 폴더를 열어주세요",
3233
"update_support_prompt": "지원 프롬프트 업데이트에 실패했습니다",
3334
"reset_support_prompt": "지원 프롬프트 재설정에 실패했습니다",
@@ -107,7 +108,8 @@
107108
},
108109
"buttons": {
109110
"save": "저장",
110-
"edit": "편집"
111+
"edit": "편집",
112+
"learn_more": "더 알아보기"
111113
},
112114
"tasks": {
113115
"canceled": "작업 오류: 사용자에 의해 중지 및 취소되었습니다.",

0 commit comments

Comments
 (0)