Skip to content

Instantly share code, notes, and snippets.

@dorianmariecom
Last active July 28, 2020 21:56
Show Gist options
  • Save dorianmariecom/581edc9235b7c6b920eca0d3d645e021 to your computer and use it in GitHub Desktop.
Save dorianmariecom/581edc9235b7c6b920eca0d3d645e021 to your computer and use it in GitHub Desktop.
diff --git a/spec/compiler/crystal/tools/init_spec.cr b/spec/compiler/crystal/tools/init_spec.cr
index 7d59a6586..49199397c 100644
--- a/spec/compiler/crystal/tools/init_spec.cr
+++ b/spec/compiler/crystal/tools/init_spec.cr
@@ -6,6 +6,7 @@ require "ini"
require "spec"
require "yaml"
require "../../../support/tempfile"
+require "../../../support/env"
private def exec_init(project_name, project_dir = nil, type = "lib", force = false, skip_existing = false)
args = [type, project_name]
@@ -41,6 +42,26 @@ end
module Crystal
describe Init::InitProject do
+ it "correctly uses git config" do
+ within_temporary_directory do
+ File.write(".gitconfig", <<-CONTENT)
+ [user]
+ email = dorian@dorianmarie.fr
+ name = Dorian Marié
+ CONTENT
+
+ with_env("GIT_CONFIG": "#{FileUtils.pwd}/.gitconfig") do
+ Crystal::Init::InitProject.new(
+ Crystal::Init::Config.new("app", "example")
+ )
+ end
+
+ with_file "example/src/LICENSE" do |file|
+ file.should contain("Dorian Marié")
+ end
+ end
+ end
+
it "has proper contents" do
within_temporary_directory do
run_init_project("lib", "example", "John Smith", "john@smith.com", "jsmith")
diff --git a/src/compiler/crystal/tools/init.cr b/src/compiler/crystal/tools/init.cr
index d5435ce1c..1c97b0bc7 100644
--- a/src/compiler/crystal/tools/init.cr
+++ b/src/compiler/crystal/tools/init.cr
@@ -98,7 +98,7 @@ module Crystal
private def self.git_config(key)
String.build do |io|
- Process.run("git", ["config", key], output: io)
+ Process.run("git", ["config", "--get", key], output: io)
end.strip.presence
end
diff --git a/src/compiler/crystal/tools/init/template/license.ecr b/src/compiler/crystal/tools/init/template/license.ecr
index 64585cbc4..3f72be5b8 100644
--- a/src/compiler/crystal/tools/init/template/license.ecr
+++ b/src/compiler/crystal/tools/init/template/license.ecr
@@ -1,6 +1,6 @@
The MIT License (MIT)
-Copyright (c) <%= Time.local.year %> <%= config.author %>
+Copyright (c) <%= Time.local.year %> <%= config.author %> <<%= config.email %>>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment