-
Notifications
You must be signed in to change notification settings - Fork 72
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refs: #2213 - Migrates git shard to main testsuite project. - Flattens out the directory structure. - Some of the deleted utils files might be necessary, `require` statements will be resolved in later commits, if that is the case. Signed-off-by: svteb <[email protected]>
- Loading branch information
Showing
6 changed files
with
159 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
require "../spec_helper" | ||
require "colorize" | ||
|
||
describe "Git" do | ||
it "'installation_found?' should show a git client was located", tags:["git"] do | ||
(GitClient.installation_found?).should be_true | ||
end | ||
|
||
it "'git_global_response()' should return the information about the git installation", tags:["git"] do | ||
(git_global_response(true)).should contain("git version") | ||
end | ||
|
||
it "'git_local_response()' should return the information about the git installation", tags:["git"] do | ||
(git_local_response(true)).should eq("") | ||
end | ||
|
||
it "'git_version()' should return the information about the git version", tags:["git"] do | ||
(git_version(git_global_response)).should match(/(([0-9]{1,3}[\.]){1,2}[0-9]{1,3})/) | ||
(git_version(git_local_response)).should contain("") | ||
end | ||
|
||
it "'git_installations()' should return the information about the git installation", tags:["git"] do | ||
(git_installation(true)).should contain("git found") | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
module GitClient | ||
DEFAULT_LOCAL_BINARY_PATH = "tools/git/linux-amd64/git" | ||
BASE_CONFIG = "./config.yml" | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
require "log" | ||
require "./utils/system_information.cr" | ||
|
||
module GitClient | ||
def self.installation_found? | ||
git_installation.includes?("git found") | ||
end | ||
|
||
def self.clone(command) | ||
Log.info { "GitClient.clone command: #{command}" } | ||
status = Process.run("git clone #{command}", | ||
shell: true, | ||
output: output = IO::Memory.new, | ||
error: stderr = IO::Memory.new) | ||
Log.info { "GitClient.clone output: #{output.to_s}" } | ||
Log.info { "GitClient.clone stderr: #{stderr.to_s}" } | ||
{status: status, output: output, error: stderr} | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
require "colorize" | ||
require "../../src/utils/utils.cr" | ||
|
||
def git_installation(verbose=false) | ||
gmsg = "No Global git version found" | ||
lmsg = "No Local git version found" | ||
ggit = git_global_response | ||
Log.for("verbose").info { ggit } if verbose | ||
|
||
global_git_version = git_version(ggit, verbose) | ||
|
||
if !global_git_version.empty? | ||
gmsg = "Global git found. Version: #{global_git_version}" | ||
stdout_success gmsg | ||
else | ||
stdout_warning gmsg | ||
end | ||
|
||
lgit = git_local_response | ||
Log.for("verbose").info { lgit } if verbose | ||
|
||
local_git_version = git_version(lgit, verbose) | ||
|
||
if !local_git_version.empty? | ||
lmsg = "Local git found. Version: #{local_git_version}" | ||
stdout_success lmsg | ||
else | ||
stdout_warning lmsg | ||
end | ||
|
||
# uncomment to fail the installation check | ||
# global_git_version = nil | ||
# local_git_version = nil | ||
# gmsg = "No Global git version found" | ||
# lmsg = "No Local git version found" | ||
if !(global_git_version && local_git_version) | ||
stdout_failure "Git not found" | ||
stdout_failure %Q( | ||
Linux installation instructions for Git can be found here: https://github.com/git-guides/install-git | ||
Install git binary with curl on Linux | ||
On Debian/Ubuntu: | ||
sudo apt-get install git-all | ||
On Fedora | ||
sudo dnf install git-all | ||
) | ||
end | ||
"#{lmsg} #{gmsg}" | ||
end | ||
|
||
def git_global_response(verbose=false) | ||
status = Process.run("git version", shell: true, output: git_response = IO::Memory.new, error: stderr = IO::Memory.new) | ||
Log.for("verbose").info { git_response } if verbose | ||
git_response.to_s | ||
end | ||
|
||
def git_local_response(verbose=false) | ||
Log.for("verbose").info { local_git_path } if verbose | ||
status = Process.run("#{local_git_path} version", shell: true, output: git_response = IO::Memory.new, error: stderr = IO::Memory.new) | ||
Log.for("verbose").info { git_response.to_s } if verbose | ||
git_response.to_s | ||
end | ||
|
||
def git_version(git_response, verbose=false) | ||
# example | ||
# git version 1.9.1 | ||
resp = git_response.match /git version (([0-9]{1,3}[\.]){1,2}[0-9]{1,3})/ | ||
Log.for("verbose").info { resp } if verbose | ||
if resp | ||
"#{resp && resp.not_nil![1]}" | ||
else | ||
"" | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
require "totem" | ||
require "colorize" | ||
require "log" | ||
require "file_utils" | ||
require "../constants.cr" | ||
|
||
def stdout_info(msg) | ||
puts msg | ||
end | ||
|
||
def stdout_success(msg) | ||
puts msg.colorize(:green) | ||
end | ||
|
||
def stdout_warning(msg) | ||
puts msg.colorize(:yellow) | ||
end | ||
|
||
def stdout_failure(msg) | ||
puts msg.colorize(:red) | ||
end | ||
|
||
def local_git_path | ||
if File.exists?(GitClient::BASE_CONFIG) | ||
config = Totem.from_file GitClient::BASE_CONFIG | ||
if config[":git_binary_path"]? && config[":git_binary_path"].as_s? | ||
return config[":git_binary_path"].as_s | ||
end | ||
end | ||
|
||
FileUtils.pwd + GitClient::DEFAULT_LOCAL_BINARY_PATH | ||
end |