diff --git a/lib/dpl/providers/pages/git.rb b/lib/dpl/providers/pages/git.rb index c2baa87fd..1b0607d03 100644 --- a/lib/dpl/providers/pages/git.rb +++ b/lib/dpl/providers/pages/git.rb @@ -26,6 +26,7 @@ class Git < Pages opt '--allow_empty_commit', 'Allow an empty commit to be created', requires: :keep_history opt '--verbose', 'Be verbose about the deploy process' opt '--local_dir DIR', 'Directory to push to GitHub Pages', default: '.' + opt '--target_dir DIR', 'Target directory within repository', default: '.' opt '--fqdn FQDN', 'Write the given domain name to the CNAME file' opt '--project_name NAME', 'Used in the commit message only (defaults to fqdn or the current repo slug)' opt '--name NAME', 'Committer name', note: 'defaults to the current git commit author name' @@ -46,10 +47,11 @@ class Git < Pages work_dir: 'Using temporary work directory %{work_dir}', committer_from_gh: 'The repo is configured to use committer user and email.', setup_dir: 'The source dir for deployment is %s', + target_dir: 'The target dir for deployment is %s', git_clone: 'Cloning the branch %{target_branch} from the remote repo', git_init: 'Initializing local git repo', git_checkout: 'Checking out orphan branch %{target_branch}', - copy_files: 'Copying %{src_dir} contents to %{work_dir}', + copy_files: 'Copying %{src_dir} contents to %{dst_dir}', git_config: 'Configuring git committer to be %{name} <%{email}>', prepare: 'Preparing to deploy %{target_branch} branch to gh-pages', git_push: 'Pushing to %{url}', @@ -59,7 +61,7 @@ class Git < Pages git_init: 'git init .', git_checkout: 'git checkout --orphan "%{target_branch}"', check_deploy_key: 'ssh -i %{key} -T git@github.com 2>&1 | grep successful > /dev/null', - copy_files: 'rsync -rl --exclude .git --delete "%{src_dir}/" .', + copy_files: 'rsync -rl --exclude .git --delete "%{src_dir}/" "%{dst_dir}"', git_config_email: 'git config user.email %{quoted_email}', git_config_name: 'git config user.name %{quoted_name}', deployment_file: 'touch "deployed at %{now} by %{name}"', @@ -82,6 +84,7 @@ def login def setup info :setup_dir, src_dir + info :target_dir, dst_dir info :committer_from_gh if committer_from_gh? info :git_config end @@ -231,6 +234,10 @@ def src_dir @src_dir ||= expand(local_dir) end + def dst_dir + @dst_dir ||= target_dir + end + def work_dir @work_dir ||= tmp_dir end diff --git a/spec/dpl/providers/pages/git_spec.rb b/spec/dpl/providers/pages/git_spec.rb index 2501f4fc7..3c1a70561 100644 --- a/spec/dpl/providers/pages/git_spec.rb +++ b/spec/dpl/providers/pages/git_spec.rb @@ -20,7 +20,7 @@ it { should have_run '[info] Deploying branch gh-pages to github.com/travis-ci/dpl.git' } it { should have_run '[info] Cloning the branch gh-pages from the remote repo' } it { should have_run 'git clone --quiet --branch="gh-pages" --depth=1 "https://token@github.com/travis-ci/dpl.git" . > /dev/null 2>&1' } - it { should have_run %(rsync -rl --exclude .git --delete "#{cwd}/" .) } + it { should have_run %(rsync -rl --exclude .git --delete "#{cwd}/" ".") } it { should have_run 'git config user.name "author name (via Travis CI)"' } it { should have_run 'git config user.email "author email"' } it { should have_run 'git add -A .' } @@ -36,7 +36,7 @@ it { should have_run '[info] Deploying branch gh-pages to github.com/travis-ci/dpl.git' } it { should have_run '[info] Using temporary work directory tmp' } it { should have_run "[info] Cloning the branch gh-pages from the remote repo" } - it { should have_run "[info] Copying #{cwd} contents to tmp" } + it { should have_run "[info] Copying #{cwd} contents to ." } it { should have_run '[info] Configuring git committer to be author name (via Travis CI) ' } it { should have_run '[info] Preparing to deploy gh-pages branch to gh-pages' } it { should have_run '[info] Pushing to github.com/travis-ci/dpl.git' } @@ -57,7 +57,7 @@ it { should have_run '[info] Initializing local git repo' } it { should have_run 'git init .' } it { should have_run 'git checkout --orphan "gh-pages"' } - it { should have_run %(rsync -rl --exclude .git --delete "#{cwd}/" .) } + it { should have_run %(rsync -rl --exclude .git --delete "#{cwd}/" ".") } it { should have_run 'git add -A .' } it { should have_run 'git commit -q -m "Deploy travis-ci/dpl to github.com/travis-ci/dpl.git:gh-pages"' } it { should have_run 'git show --stat-count=10 HEAD' } @@ -74,9 +74,15 @@ end describe 'given --local_dir ./dir --verbose' do - it { should have_run "rsync -rl --exclude .git --delete \"#{cwd}/dir/\" ." } + it { should have_run "rsync -rl --exclude .git --delete \"#{cwd}/dir/\" \".\"" } it { should have_run "[info] The source dir for deployment is #{cwd}/dir" } - it { should have_run "[info] Copying #{cwd}/dir contents to tmp" } + it { should have_run "[info] Copying #{cwd}/dir contents to ." } + end + + describe 'given --target_dir ./dir --verbose' do + it { should have_run "rsync -rl --exclude .git --delete \"#{cwd}/\" \"./dir\"" } + it { should have_run "[info] The target dir for deployment is ./dir" } + it { should have_run "[info] Copying #{cwd} contents to ./dir" } end describe 'given --fqdn fqdn.com' do