From 753d346769d2f5c58ba27d5cd21f17a75e4f000a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Die=C3=9Fner?= Date: Tue, 22 Dec 2020 10:30:38 +0100 Subject: [PATCH 01/17] Added runCloneRepository --- runners/console/index.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/runners/console/index.ts b/runners/console/index.ts index 04feb102..939c174f 100644 --- a/runners/console/index.ts +++ b/runners/console/index.ts @@ -143,6 +143,10 @@ export class Console extends Runner { return result; } + runCloneRepository(step: Step, command: Command): RunResult { + return null; + } + async assertInstallDevonfwIde(step: Step, command: Command, result: RunResult) { let installedTools = command.parameters[0]; From a813fecb591106fca656377cfc37ec7cd15d8b5b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Die=C3=9Fner?= Date: Tue, 22 Dec 2020 11:58:33 +0100 Subject: [PATCH 02/17] runCloneRepository and Assertion implemented --- runners/console/index.ts | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/runners/console/index.ts b/runners/console/index.ts index 939c174f..e6494bc3 100644 --- a/runners/console/index.ts +++ b/runners/console/index.ts @@ -144,7 +144,16 @@ export class Console extends Runner { } runCloneRepository(step: Step, command: Command): RunResult { - return null; + let result = new RunResult(); + result.returnCode = 0; + + let workspaceDir = path.join(this.getWorkingDirectory(), "devonfw", "workspaces", "main"); + let directorypath = path.join(workspaceDir, command.parameters[0]); + + this.createFolder(directorypath, false); + this.executeCommandSync("git clone" + command.parameters[1], directorypath, result); + + return result; } async assertInstallDevonfwIde(step: Step, command: Command, result: RunResult) { @@ -226,6 +235,15 @@ export class Console extends Runner { .fileContains(filepath, content); } + async assertCloneRepository(step: Step, command: Command, result: RunResult) { + let repository = command.parameters[1] + let repoName = repository.substr(repository.lastIndexOf("/"),repository.lastIndexOf(".")); + new Assertions() + .noErrorCode(result) + .noException(result) + .directoryExits(path.join(this.getWorkingDirectory(), "devonfw", "workspaces", "main", command.parameters[0], repoName)); + } + private executeCommandSync(command: string, directory: string, result: RunResult, input?: string) { if(result.returnCode != 0) return; From 60f8ca995bca72db82170f813f87c14c93582d3a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Die=C3=9Fner?= Date: Tue, 22 Dec 2020 12:14:25 +0100 Subject: [PATCH 03/17] assertCloneRepository Errors fixed --- runners/console/index.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/runners/console/index.ts b/runners/console/index.ts index e6494bc3..8f9c3a3b 100644 --- a/runners/console/index.ts +++ b/runners/console/index.ts @@ -151,7 +151,7 @@ export class Console extends Runner { let directorypath = path.join(workspaceDir, command.parameters[0]); this.createFolder(directorypath, false); - this.executeCommandSync("git clone" + command.parameters[1], directorypath, result); + this.executeCommandSync("git clone " + command.parameters[1], directorypath, result); return result; } @@ -237,7 +237,7 @@ export class Console extends Runner { async assertCloneRepository(step: Step, command: Command, result: RunResult) { let repository = command.parameters[1] - let repoName = repository.substr(repository.lastIndexOf("/"),repository.lastIndexOf(".")); + let repoName = repository.slice(repository.lastIndexOf("/"), -4); new Assertions() .noErrorCode(result) .noException(result) From 0975a6eab39ad594f03c076c963ab028643e0004 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Die=C3=9Fner?= Date: Tue, 22 Dec 2020 13:46:27 +0100 Subject: [PATCH 04/17] katacoda runner for cloneRepository implemented --- runners/katacoda/index.ts | 15 +++++++++++++++ runners/katacoda/templates/cloneRepository.md | 15 +++++++++++++++ 2 files changed, 30 insertions(+) create mode 100644 runners/katacoda/templates/cloneRepository.md diff --git a/runners/katacoda/index.ts b/runners/katacoda/index.ts index d0450eab..ddcd3616 100644 --- a/runners/katacoda/index.ts +++ b/runners/katacoda/index.ts @@ -209,6 +209,21 @@ export class Katacoda extends Runner { } + runCloneRepository(step: Step, command: Command): RunResult { + + let cdCommand = this.changeCurrentDir(path.join("/root", "devonfw", "workspaces", "main")); + let workspaceDir = path.join("devonfw", "workspaces", "main"); + let directoryPath = path.join(workspaceDir, command.parameters[0]).replace(/\\/g, "/"); + + this.steps.push({ + "title": "Clones Repository " + command.parameters[1], + "text": "step" + this.stepsCount + ".md" + }); + + this.renderTemplate("cloneRepository.md", this.outputPathTutorial + "step" + (this.stepsCount++) + ".md", { text: step.text, textAfter: step.textAfter, cdCommand: cdCommand, directoryPath: directoryPath, repository: command.parameters[1]}); + return null; + } + private renderTemplate(name: string, targetPath: string, variables) { let template = fs.readFileSync(path.join(this.getRunnerDirectory(),"templates", name), 'utf8'); let result = ejs.render(template, variables); diff --git a/runners/katacoda/templates/cloneRepository.md b/runners/katacoda/templates/cloneRepository.md new file mode 100644 index 00000000..6fe98184 --- /dev/null +++ b/runners/katacoda/templates/cloneRepository.md @@ -0,0 +1,15 @@ +<%= text; %> + +<%= cdCommand; %> + +If the parent directories aren't already in the project, 'mkdir -p' will create them for you. + +`mkdir -p <%= directoryPath; %>`{{execute}} + +`cd <%= directoryPath; %>`{{execute}} + +Now clone the repository to your local directory. + +`git clone <%= repository; %>`{{execute}} + +<%= textAfter; %> \ No newline at end of file From da2ac37e01a1f0e571cb71b98abb668672a65759 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcel=20Die=C3=9Fner?= Date: Tue, 22 Dec 2020 13:57:30 +0100 Subject: [PATCH 05/17] katacoda runner for cloneRepository implemented --- runners/katacoda/index.ts | 15 +++++++++++++++ runners/katacoda/templates/cloneRepository.md | 15 +++++++++++++++ 2 files changed, 30 insertions(+) create mode 100644 runners/katacoda/templates/cloneRepository.md diff --git a/runners/katacoda/index.ts b/runners/katacoda/index.ts index d0450eab..ddcd3616 100644 --- a/runners/katacoda/index.ts +++ b/runners/katacoda/index.ts @@ -209,6 +209,21 @@ export class Katacoda extends Runner { } + runCloneRepository(step: Step, command: Command): RunResult { + + let cdCommand = this.changeCurrentDir(path.join("/root", "devonfw", "workspaces", "main")); + let workspaceDir = path.join("devonfw", "workspaces", "main"); + let directoryPath = path.join(workspaceDir, command.parameters[0]).replace(/\\/g, "/"); + + this.steps.push({ + "title": "Clones Repository " + command.parameters[1], + "text": "step" + this.stepsCount + ".md" + }); + + this.renderTemplate("cloneRepository.md", this.outputPathTutorial + "step" + (this.stepsCount++) + ".md", { text: step.text, textAfter: step.textAfter, cdCommand: cdCommand, directoryPath: directoryPath, repository: command.parameters[1]}); + return null; + } + private renderTemplate(name: string, targetPath: string, variables) { let template = fs.readFileSync(path.join(this.getRunnerDirectory(),"templates", name), 'utf8'); let result = ejs.render(template, variables); diff --git a/runners/katacoda/templates/cloneRepository.md b/runners/katacoda/templates/cloneRepository.md new file mode 100644 index 00000000..6fe98184 --- /dev/null +++ b/runners/katacoda/templates/cloneRepository.md @@ -0,0 +1,15 @@ +<%= text; %> + +<%= cdCommand; %> + +If the parent directories aren't already in the project, 'mkdir -p' will create them for you. + +`mkdir -p <%= directoryPath; %>`{{execute}} + +`cd <%= directoryPath; %>`{{execute}} + +Now clone the repository to your local directory. + +`git clone <%= repository; %>`{{execute}} + +<%= textAfter; %> \ No newline at end of file From 20f4291f7b9cd1398f3f7edc7ad9909d490496d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcel=20Die=C3=9Fner?= Date: Tue, 22 Dec 2020 15:33:49 +0100 Subject: [PATCH 06/17] resolved issues of reviews --- runners/console/index.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/runners/console/index.ts b/runners/console/index.ts index 8f9c3a3b..cf876782 100644 --- a/runners/console/index.ts +++ b/runners/console/index.ts @@ -147,10 +147,9 @@ export class Console extends Runner { let result = new RunResult(); result.returnCode = 0; - let workspaceDir = path.join(this.getWorkingDirectory(), "devonfw", "workspaces", "main"); - let directorypath = path.join(workspaceDir, command.parameters[0]); + let directorypath = path.join(this.getWorkingDirectory(), "devonfw", "workspaces", "main", command.parameters[0]); - this.createFolder(directorypath, false); + this.createFolder(directorypath, true); this.executeCommandSync("git clone " + command.parameters[1], directorypath, result); return result; @@ -236,12 +235,13 @@ export class Console extends Runner { } async assertCloneRepository(step: Step, command: Command, result: RunResult) { - let repository = command.parameters[1] + let repository = command.parameters[1]; let repoName = repository.slice(repository.lastIndexOf("/"), -4); new Assertions() .noErrorCode(result) .noException(result) - .directoryExits(path.join(this.getWorkingDirectory(), "devonfw", "workspaces", "main", command.parameters[0], repoName)); + .directoryExits(path.join(this.getWorkingDirectory(), "devonfw", "workspaces", "main", command.parameters[0], repoName)) + .directoryNotEmpty(path.join(this.getWorkingDirectory(), "devonfw", "workspaces", "main", command.parameters[0], repoName)); } private executeCommandSync(command: string, directory: string, result: RunResult, input?: string) { From dcfbcb8b1644d3511da5820d187c9af1d4565e9a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcel=20Die=C3=9Fner?= Date: Wed, 23 Dec 2020 14:13:03 +0100 Subject: [PATCH 07/17] Added documentation --- documentation/Functions.md | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/documentation/Functions.md b/documentation/Functions.md index a9eefb1a..67b0b71a 100644 --- a/documentation/Functions.md +++ b/documentation/Functions.md @@ -6,6 +6,7 @@ The following functions are already implemented: * createDevon4jProject * buildJava * createFile +* cloneRepository *** @@ -96,3 +97,14 @@ A placeholder is optional. If you do not define a placeholder, the content in th Please try not to use custom placeholders. Keep in mind that you might want to build the project before changing them. Custom placeholders with a comment-syntax (e.g. "//PLACEHOLDER") will be removed by the console-environment and others might cause errors. *** + +### cloneRepository +#### parameter +1. Path into which the repository is to be cloned, relative to workspace +2. Git Repository URL +#### example +cloneRepository("", "https://github.com/devonfw-forge/tutorial-compiler.git") + +Repository will be cloned directly into the workspace directory. + +*** From b0fcd2fda840b0e300bcc978eea7c4792edcf129 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcel=20Die=C3=9Fner?= Date: Wed, 23 Dec 2020 14:15:42 +0100 Subject: [PATCH 08/17] Fixed documentation --- documentation/Functions.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/documentation/Functions.md b/documentation/Functions.md index 67b0b71a..9c8629f8 100644 --- a/documentation/Functions.md +++ b/documentation/Functions.md @@ -100,8 +100,8 @@ Please try not to use custom placeholders. Keep in mind that you might want to b ### cloneRepository #### parameter -1. Path into which the repository is to be cloned, relative to workspace -2. Git Repository URL +1. Path into which the repository is to be cloned, relative to workspace. +2. Git repository URL #### example cloneRepository("", "https://github.com/devonfw-forge/tutorial-compiler.git") From dccc9831ab5456c53420c4cf65bac27e2b0f31fe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcel=20Die=C3=9Fner?= Date: Wed, 23 Dec 2020 14:55:26 +0100 Subject: [PATCH 09/17] Added Case for Empty String --- runners/katacoda/index.ts | 10 +++++++--- .../katacoda/templates/cloneRepositoryEmptyString.md | 9 +++++++++ 2 files changed, 16 insertions(+), 3 deletions(-) create mode 100644 runners/katacoda/templates/cloneRepositoryEmptyString.md diff --git a/runners/katacoda/index.ts b/runners/katacoda/index.ts index ddcd3616..c54c0e9f 100644 --- a/runners/katacoda/index.ts +++ b/runners/katacoda/index.ts @@ -212,15 +212,19 @@ export class Katacoda extends Runner { runCloneRepository(step: Step, command: Command): RunResult { let cdCommand = this.changeCurrentDir(path.join("/root", "devonfw", "workspaces", "main")); - let workspaceDir = path.join("devonfw", "workspaces", "main"); - let directoryPath = path.join(workspaceDir, command.parameters[0]).replace(/\\/g, "/"); + let directoryPath = path.join(command.parameters[0]).replace(/\\/g, "/"); this.steps.push({ "title": "Clones Repository " + command.parameters[1], "text": "step" + this.stepsCount + ".md" }); - this.renderTemplate("cloneRepository.md", this.outputPathTutorial + "step" + (this.stepsCount++) + ".md", { text: step.text, textAfter: step.textAfter, cdCommand: cdCommand, directoryPath: directoryPath, repository: command.parameters[1]}); + if(directoryPath.trim() == "") { + this.renderTemplate("cloneRepositoryEmptyString.md", this.outputPathTutorial + "step" + (this.stepsCount++) + ".md", {text: step.text, textAfter: step.textAfter, cdCommand: cdCommand, repository: command.parameters[1]}); + } else { + this.renderTemplate("cloneRepository.md", this.outputPathTutorial + "step" + (this.stepsCount++) + ".md", { text: step.text, textAfter: step.textAfter, cdCommand: cdCommand, directoryPath: directoryPath, repository: command.parameters[1]}); + } + return null; } diff --git a/runners/katacoda/templates/cloneRepositoryEmptyString.md b/runners/katacoda/templates/cloneRepositoryEmptyString.md new file mode 100644 index 00000000..eaf1f2e1 --- /dev/null +++ b/runners/katacoda/templates/cloneRepositoryEmptyString.md @@ -0,0 +1,9 @@ +<%= text; %> + +<%= cdCommand; %> + +Empty String was given so repository will be cloned to current directory. + +`git clone <%= repository; %>`{{execute}} + +<%= textAfter; %> \ No newline at end of file From 4bf59405f4ad57ad1de0a333561a879dade7b629 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcel=20Die=C3=9Fner?= Date: Wed, 23 Dec 2020 14:58:59 +0100 Subject: [PATCH 10/17] Added second example in documentation --- documentation/Functions.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/documentation/Functions.md b/documentation/Functions.md index 1ce6f3cc..7f34a462 100644 --- a/documentation/Functions.md +++ b/documentation/Functions.md @@ -115,7 +115,8 @@ Please try not to use custom placeholders. Keep in mind that you might want to b 2. Git repository URL #### example cloneRepository("", "https://github.com/devonfw-forge/tutorial-compiler.git") - Repository will be cloned directly into the workspace directory. +cloneRepository("devonfw-forge", "https://github.com/devonfw-forge/tutorial-compiler.git") +Repository will be cloned into a newly created subdirectory devonfw-forge. *** \ No newline at end of file From 8e09849c81bb6a244fbe8f5f1802b5f15d31a1c9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcel=20Die=C3=9Fner?= Date: Wed, 23 Dec 2020 15:21:51 +0100 Subject: [PATCH 11/17] Fixed if statement for correct result --- runners/katacoda/index.ts | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/runners/katacoda/index.ts b/runners/katacoda/index.ts index 6f1627ca..5cd3b930 100644 --- a/runners/katacoda/index.ts +++ b/runners/katacoda/index.ts @@ -238,10 +238,11 @@ export class Katacoda extends Runner { "text": "step" + this.stepsCount + ".md" }); - if(directoryPath.trim() == "") { - this.renderTemplate("cloneRepositoryEmptyString.md", this.outputPathTutorial + "step" + (this.stepsCount++) + ".md", {text: step.text, textAfter: step.textAfter, cdCommand: cdCommand, repository: command.parameters[1]}); - } else { + // checks if path is an empty string + if(Boolean(command.parameters[0].trim())) { this.renderTemplate("cloneRepository.md", this.outputPathTutorial + "step" + (this.stepsCount++) + ".md", { text: step.text, textAfter: step.textAfter, cdCommand: cdCommand, directoryPath: directoryPath, repository: command.parameters[1]}); + } else { + this.renderTemplate("cloneRepositoryEmptyString.md", this.outputPathTutorial + "step" + (this.stepsCount++) + ".md", {text: step.text, textAfter: step.textAfter, cdCommand: cdCommand, repository: command.parameters[1]}); } return null; From b6c22a3d592a8c557093bfe92e507f15c12e0191 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcel=20Die=C3=9Fner?= Date: Wed, 30 Dec 2020 12:04:46 +0100 Subject: [PATCH 12/17] check for empty string now in template and assertCloneRepository checks git status --- runners/console/index.ts | 12 ++++++++++++ runners/katacoda/index.ts | 8 +------- runners/katacoda/templates/cloneRepository.md | 2 ++ .../katacoda/templates/cloneRepositoryEmptyString.md | 9 --------- 4 files changed, 15 insertions(+), 16 deletions(-) delete mode 100644 runners/katacoda/templates/cloneRepositoryEmptyString.md diff --git a/runners/console/index.ts b/runners/console/index.ts index 13143d9c..d10a7ba4 100644 --- a/runners/console/index.ts +++ b/runners/console/index.ts @@ -246,6 +246,18 @@ export class Console extends Runner { async assertCloneRepository(step: Step, command: Command, result: RunResult) { let repository = command.parameters[1]; let repoName = repository.slice(repository.lastIndexOf("/"), -4); + let directorypath = path.join(this.getWorkingDirectory(), "devonfw", "workspaces", "main", command.parameters[0], repoName); + + let process = child_process.spawnSync("git status -s", { shell: true, cwd: directorypath }); + if(process.status != 0) { + result.returnCode = process.status; + } + // checks if stdout is not empty + if(Boolean(process.stdout.toString())) { + console.log("Current git status: " + process.stdout.toString()); + result.returnCode = 1; + } + new Assertions() .noErrorCode(result) .noException(result) diff --git a/runners/katacoda/index.ts b/runners/katacoda/index.ts index 5cd3b930..2924866e 100644 --- a/runners/katacoda/index.ts +++ b/runners/katacoda/index.ts @@ -238,13 +238,7 @@ export class Katacoda extends Runner { "text": "step" + this.stepsCount + ".md" }); - // checks if path is an empty string - if(Boolean(command.parameters[0].trim())) { - this.renderTemplate("cloneRepository.md", this.outputPathTutorial + "step" + (this.stepsCount++) + ".md", { text: step.text, textAfter: step.textAfter, cdCommand: cdCommand, directoryPath: directoryPath, repository: command.parameters[1]}); - } else { - this.renderTemplate("cloneRepositoryEmptyString.md", this.outputPathTutorial + "step" + (this.stepsCount++) + ".md", {text: step.text, textAfter: step.textAfter, cdCommand: cdCommand, repository: command.parameters[1]}); - } - + this.renderTemplate("cloneRepository.md", this.outputPathTutorial + "step" + (this.stepsCount++) + ".md", { text: step.text, textAfter: step.textAfter, cdCommand: cdCommand, directoryPath: directoryPath, repository: command.parameters[1], string: command.parameters[0].trim() }); return null; } diff --git a/runners/katacoda/templates/cloneRepository.md b/runners/katacoda/templates/cloneRepository.md index 6fe98184..37415b68 100644 --- a/runners/katacoda/templates/cloneRepository.md +++ b/runners/katacoda/templates/cloneRepository.md @@ -2,11 +2,13 @@ <%= cdCommand; %> +<% if (string) { %> If the parent directories aren't already in the project, 'mkdir -p' will create them for you. `mkdir -p <%= directoryPath; %>`{{execute}} `cd <%= directoryPath; %>`{{execute}} +<% } %> Now clone the repository to your local directory. diff --git a/runners/katacoda/templates/cloneRepositoryEmptyString.md b/runners/katacoda/templates/cloneRepositoryEmptyString.md deleted file mode 100644 index eaf1f2e1..00000000 --- a/runners/katacoda/templates/cloneRepositoryEmptyString.md +++ /dev/null @@ -1,9 +0,0 @@ -<%= text; %> - -<%= cdCommand; %> - -Empty String was given so repository will be cloned to current directory. - -`git clone <%= repository; %>`{{execute}} - -<%= textAfter; %> \ No newline at end of file From c67c6c0885a738e7a20f1c2381a879426943d600 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcel=20Die=C3=9Fner?= Date: Wed, 30 Dec 2020 15:09:52 +0100 Subject: [PATCH 13/17] Removed Statementcast to Boolean --- runners/console/index.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/runners/console/index.ts b/runners/console/index.ts index d10a7ba4..32478c91 100644 --- a/runners/console/index.ts +++ b/runners/console/index.ts @@ -252,8 +252,8 @@ export class Console extends Runner { if(process.status != 0) { result.returnCode = process.status; } - // checks if stdout is not empty - if(Boolean(process.stdout.toString())) { + + if(process.stdout.toString()) { console.log("Current git status: " + process.stdout.toString()); result.returnCode = 1; } From 44a1a437275b1d5a90452efb746804ee9e38609b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcel=20Die=C3=9Fner?= Date: Wed, 6 Jan 2021 09:15:05 +0100 Subject: [PATCH 14/17] Added assertion repositoryIsClean to check for git status result --- assertions/index.ts | 6 ++++++ assertions/repositoryIsClean.ts | 12 ++++++++++++ runners/console/index.ts | 14 +++----------- 3 files changed, 21 insertions(+), 11 deletions(-) create mode 100644 assertions/repositoryIsClean.ts diff --git a/assertions/index.ts b/assertions/index.ts index 76febd25..ed95714c 100644 --- a/assertions/index.ts +++ b/assertions/index.ts @@ -7,6 +7,7 @@ import { DirectoryExist } from "./directoryExist"; import { FileExist } from "./fileExist"; import { DirectoryNotEmpty } from "./directoryNotEmpty"; import { FileContains } from "./fileContains"; +import { RepositoryIsClean } from "./repositoryIsClean"; export class Assertions { @@ -40,4 +41,9 @@ export class Assertions { FileContains.run(filepath, content); return this; } + + public repositoryIsClean(directory: string): Assertions { + RepositoryIsClean.run(directory); + return this; + } } \ No newline at end of file diff --git a/assertions/repositoryIsClean.ts b/assertions/repositoryIsClean.ts new file mode 100644 index 00000000..83e45ae2 --- /dev/null +++ b/assertions/repositoryIsClean.ts @@ -0,0 +1,12 @@ +import * as child_process from "child_process"; + +export class RepositoryIsClean { + public static run(directory: string): void { + let process = child_process.spawnSync("git status -s", { shell: true, cwd: directory }); + if(process.status != 0) { + throw new Error("'git status -s' execution in directory " + directory + " returned error.") + } else if(process.stdout.toString()) { + throw new Error("Repository in directory " + directory + " is not clean. Current Status: " + process.stdout.toString()); + } + } +} diff --git a/runners/console/index.ts b/runners/console/index.ts index 32478c91..e2238d9b 100644 --- a/runners/console/index.ts +++ b/runners/console/index.ts @@ -8,6 +8,7 @@ import { ConsolePlatform } from "./consoleInterfaces"; import * as path from 'path'; import * as child_process from "child_process"; import * as fs from "fs"; +import { O_DIRECTORY } from "constants"; export class Console extends Runner { @@ -248,21 +249,12 @@ export class Console extends Runner { let repoName = repository.slice(repository.lastIndexOf("/"), -4); let directorypath = path.join(this.getWorkingDirectory(), "devonfw", "workspaces", "main", command.parameters[0], repoName); - let process = child_process.spawnSync("git status -s", { shell: true, cwd: directorypath }); - if(process.status != 0) { - result.returnCode = process.status; - } - - if(process.stdout.toString()) { - console.log("Current git status: " + process.stdout.toString()); - result.returnCode = 1; - } - new Assertions() .noErrorCode(result) .noException(result) .directoryExits(path.join(this.getWorkingDirectory(), "devonfw", "workspaces", "main", command.parameters[0], repoName)) - .directoryNotEmpty(path.join(this.getWorkingDirectory(), "devonfw", "workspaces", "main", command.parameters[0], repoName)); + .directoryNotEmpty(path.join(this.getWorkingDirectory(), "devonfw", "workspaces", "main", command.parameters[0], repoName)) + .repositoryIsClean(directorypath); } private executeCommandSync(command: string, directory: string, result: RunResult, input?: string) { From ebf9579f2fb807bca1570543a840c5152192cd9d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcel=20Die=C3=9Fner?= Date: Wed, 6 Jan 2021 09:21:50 +0100 Subject: [PATCH 15/17] removed wrong import --- runners/console/index.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/runners/console/index.ts b/runners/console/index.ts index e2238d9b..18fca0f4 100644 --- a/runners/console/index.ts +++ b/runners/console/index.ts @@ -8,7 +8,6 @@ import { ConsolePlatform } from "./consoleInterfaces"; import * as path from 'path'; import * as child_process from "child_process"; import * as fs from "fs"; -import { O_DIRECTORY } from "constants"; export class Console extends Runner { From af82294b610c710b1a683cfa4d93aed03eeb0e52 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcel=20Die=C3=9Fner?= Date: Wed, 6 Jan 2021 11:02:11 +0100 Subject: [PATCH 16/17] changed string to directoryPath in cloneRepository.md --- runners/katacoda/index.ts | 8 ++++++-- runners/katacoda/templates/cloneRepository.md | 2 +- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/runners/katacoda/index.ts b/runners/katacoda/index.ts index 2924866e..a4301400 100644 --- a/runners/katacoda/index.ts +++ b/runners/katacoda/index.ts @@ -231,14 +231,18 @@ export class Katacoda extends Runner { runCloneRepository(step: Step, command: Command): RunResult { let cdCommand = this.changeCurrentDir(path.join("/root", "devonfw", "workspaces", "main")); - let directoryPath = path.join(command.parameters[0]).replace(/\\/g, "/"); + let directoryPath = ""; + if(command.parameters[0].trim()) { + directoryPath = path.join(command.parameters[0]).replace(/\\/g, "/"); + } + this.steps.push({ "title": "Clones Repository " + command.parameters[1], "text": "step" + this.stepsCount + ".md" }); - this.renderTemplate("cloneRepository.md", this.outputPathTutorial + "step" + (this.stepsCount++) + ".md", { text: step.text, textAfter: step.textAfter, cdCommand: cdCommand, directoryPath: directoryPath, repository: command.parameters[1], string: command.parameters[0].trim() }); + this.renderTemplate("cloneRepository.md", this.outputPathTutorial + "step" + (this.stepsCount++) + ".md", { text: step.text, textAfter: step.textAfter, cdCommand: cdCommand, directoryPath: directoryPath, repository: command.parameters[1] }); return null; } diff --git a/runners/katacoda/templates/cloneRepository.md b/runners/katacoda/templates/cloneRepository.md index 37415b68..626111ca 100644 --- a/runners/katacoda/templates/cloneRepository.md +++ b/runners/katacoda/templates/cloneRepository.md @@ -2,7 +2,7 @@ <%= cdCommand; %> -<% if (string) { %> +<% if (directoryPath) { %> If the parent directories aren't already in the project, 'mkdir -p' will create them for you. `mkdir -p <%= directoryPath; %>`{{execute}} From 584712019c34d906a1665c0fe4e034c0c195714f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcel=20Die=C3=9Fner?= Date: Wed, 6 Jan 2021 11:32:48 +0100 Subject: [PATCH 17/17] Change to correct current dir --- runners/katacoda/index.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/runners/katacoda/index.ts b/runners/katacoda/index.ts index a4301400..8bac4436 100644 --- a/runners/katacoda/index.ts +++ b/runners/katacoda/index.ts @@ -234,6 +234,7 @@ export class Katacoda extends Runner { let directoryPath = ""; if(command.parameters[0].trim()) { directoryPath = path.join(command.parameters[0]).replace(/\\/g, "/"); + this.currentDir = path.join(this.currentDir, directoryPath); }