From ea40bfb6ecea241512a332e90864102f21ad7e0b Mon Sep 17 00:00:00 2001 From: Yuki Inoue Date: Sun, 20 Dec 2015 01:46:20 +0900 Subject: [PATCH 1/2] Copy user config in git deployment The original repo may have it's own user configuration, which should be inherited in the deployment repo. This commits add the user config copy logic. --- lib/octopress-deploy/git.rb | 40 +++++++++++++++++++++++++++++-------- 1 file changed, 32 insertions(+), 8 deletions(-) diff --git a/lib/octopress-deploy/git.rb b/lib/octopress-deploy/git.rb index 9a37f22..c0263f7 100644 --- a/lib/octopress-deploy/git.rb +++ b/lib/octopress-deploy/git.rb @@ -21,6 +21,7 @@ def push if File.exist?(@local) check_branch init_repo + copy_user_config puts "Syncing #{@local.sub(Dir.pwd.strip+'/', '')} files to #{@repo}." FileUtils.cd @deploy_dir do git_pull @@ -86,6 +87,9 @@ def self.default_config(options={}) # def init_repo return if check_deploy_dir + + need_initial_commits=false + FileUtils.mkdir_p @deploy_dir FileUtils.cd @deploy_dir do if Dir[@deploy_dir+'/*'].empty? @@ -100,18 +104,38 @@ def init_repo if git_pull `git branch -m #{@branch}` - # If no branch exists on remote, create one locally. + # If no branch exists on remote, we need to create one locally. else - `echo "initialize deploy repo" > _` - `git add .` - `git commit -m \"initial commit\"` - `git branch -m #{@branch}` - `git rm _` - `git add -u` - `git commit -m 'cleanup'` + need_initial_commits=true end end end + + make_initial_commits if need_initial_commits + end + + def make_initial_commits + copy_user_config + FileUtils.cd @deploy_dir do + `echo "initialize deploy repo" > _` + `git add .` + `git commit -m \"initial commit\"` + `git branch -m #{@branch}` + `git rm _` + `git add -u` + `git commit -m 'cleanup'` + end + end + + # Set user config to be used for commit. + # + def copy_user_config + user_name=`git config user.name`.chomp + user_email=`git config user.email`.chomp + FileUtils.cd @deploy_dir do + `git config user.name "#{user_name}"` + `git config user.email "#{user_email}"` + end end def git_push From 856c7bccc61b32bdceddad837f0a3948cbd05f55 Mon Sep 17 00:00:00 2001 From: Yuki Inoue Date: Sun, 20 Dec 2015 04:46:09 +0900 Subject: [PATCH 2/2] Removed unused logic of check_deploy_dir In git.rb, check_deploy_dir method was called but did nothing, so removed it; it is called in init_repo method, but the result of it does not affect the execution logic. If the check is failse, then the init_repo method does nothing anyway. --- lib/octopress-deploy/git.rb | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/lib/octopress-deploy/git.rb b/lib/octopress-deploy/git.rb index c0263f7..3a2240d 100644 --- a/lib/octopress-deploy/git.rb +++ b/lib/octopress-deploy/git.rb @@ -21,7 +21,6 @@ def push if File.exist?(@local) check_branch init_repo - copy_user_config puts "Syncing #{@local.sub(Dir.pwd.strip+'/', '')} files to #{@repo}." FileUtils.cd @deploy_dir do git_pull @@ -58,15 +57,6 @@ def check_branch end end - # Check to see if local deployment dir is configured to deploy. - # - def check_deploy_dir - if Dir.exist? @deploy_dir - FileUtils.cd @deploy_dir do - return `git remote -v`.include? @repo - end - end - end def self.default_config(options={}) config = <<-CONFIG @@ -86,7 +76,6 @@ def self.default_config(options={}) # If necessary create deploy directory and initialize it with deployment remote. # def init_repo - return if check_deploy_dir need_initial_commits=false @@ -111,11 +100,12 @@ def init_repo end end + copy_user_config + make_initial_commits if need_initial_commits end def make_initial_commits - copy_user_config FileUtils.cd @deploy_dir do `echo "initialize deploy repo" > _` `git add .`