Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Git Force-Push Deploy Pushes Root Instead of Build Dir #114

Open
JustinHardage opened this issue Dec 21, 2015 · 18 comments
Open

Git Force-Push Deploy Pushes Root Instead of Build Dir #114

JustinHardage opened this issue Dec 21, 2015 · 18 comments

Comments

@JustinHardage
Copy link

I'm trying to push my middleman build directory to a GitHub Organization Page. This means that my GitHub repo master branch needs to get the output of a bundle exec middleman build command.

However, I haven't found any combination of options with deploy.method = :git that actually does this. I always get the root of the project - e.g. where the Gemfile lives - instead of something that GitHub Pages would recognize as a site with an index.html file.

How can I deploy to a GitHub Pages site?

#config.rb
activate :deploy do |deploy|
  deploy.method = :git
  deploy.remote   = 'https://github.com/FiercePunchStudios/deploy-test.git'
  deploy.branch   = 'master'
end
#Gemfile
source 'http://rubygems.org'
gem "middleman", "~> 3.4.0"
gem 'middleman-deploy', '~> 1.0'
@juanpabloe
Copy link

Same happening here.

# Gemfile

source "http://rubygems.org"
gem "middleman", '3.4.1'
gem "middleman-autoprefixer"
gem "middleman-deploy"
# config.rb

configure :build do
  # Relative assets needed to deploy to Github Pages
  activate :relative_assets
end

activate :deploy do |deploy|
  deploy.build_before = true
  deploy.method = :git
end

$ ruby -v -> ruby 2.2.3p173

@hello-jason
Copy link

I came here to report this very issue. I've been using middleman-deploy for years without issue, yet this recently started pushing up the entire project rather than just the build folder.

@hovancik
Copy link

same problem here. it does push all project, not build folder. (2.0.0 alpha)

@mehowte
Copy link

mehowte commented Dec 26, 2015

In case you need temporary quick fix, middleman deploy works if there are no files on the master branch.
I work from development branch so this is what works for me:

git checkout master && sudo rm -r Gemfile.lock build && git checkout development && middleman deploy

YMMV though

@toobulkeh
Copy link

Hmm, this appears to be a git issue. I tried locking all old versions of middleman and it's nothing there.

@hovancik
Copy link

Guys, I forked jekyll-github-deploy into https://github.com/hovancik/middleman-github-deploy, you might wanna check it out. For now it solved problem with middleman-deploy. It's a bit different approach, but you can easy deploy your site to GithubPages with it. Works for me.

@robinbortlik
Copy link

I fixed this issue, by removing build directory before each deploy. For this purposes I use small extension

#lib/build_cleaner.rb

class BuildCleaner < Middleman::Extension

  def initialize(app, options_hash={}, &block)
    super
    FileUtils.rm_rf app.config[:build_dir]
  end

end

::Middleman::Extensions.register(:build_cleaner, BuildCleaner)
#config.rb

require_relative "./lib/build_cleaner"

configure :build do
  activate :build_cleaner
end

@christopherjanzen
Copy link

@robinbortlik I've found that your solution of deleting the build directory also is working for me. Where did you put this require in your config? I'm not sure when or why this started happening as everything was working fine for me about a week ago and I haven't changed anything that I know of since then.

@JustinHardage
Copy link
Author

@robinbortlik 's fix worked for me. Any chance we can get this behavior as a default in middleman-deploy?

@robinbortlik
Copy link

@christopherjanzen @JustinHardage I'm glad that it helped. I put my require at the top of config.rb file. I also have no explanation why it stopped working. But I don't think, it should be included in the middleman deploy. This is more a hotfix. The reason why middleman don't delete whole build folder is to speedup build process. I guess. :)

@colindensem
Copy link

Also stumbled into this, thought I was going mad initially, so thanks for posting!
The fix/tweak above resolves for me under mint/2.2.2 and git 1.9.1.
HTH.

@ryankbales
Copy link

Deleting build directory before each deploy made this work for me. Not sure what needs to be done to get this fixed.

@MinasMazar
Copy link

I've done some tests and that's my experience. I hope it could help.

In root project git remote -v gives

origin [email protected]:source/of/my/project.git
gh-pages [email protected]:username/username.github.io.git

After the first middleman build (or first deploy with build-before enabled), the build directory became a git repo itself and git remote -v gives

origin [email protected]:username/username.github.io.git

That's ok. But calling again middleman build you can see in the output

identical build/stylesheets/site.css
identical build/images/middleman-logo.svg
identical build/javascripts/all.js
identical build/index.html
remove build/.gitignore
remove build/.git/objects/69/57aee4a38c4390d330570ae8a4989907911b56
remove build/.git/objects/2b/ecd765c79234b8662c575fac6c259ba87d033c
remove build/.git/objects/ff/d595503b2671ec3550df0b075ef60d7f535579
remove build/.git/objects/a5/e8ac2a41bdbef16c39fef16c69e4562db9c171
remove build/.git/objects/fa/2811b4915660d72191193c7bf5ef85750bbc4e
remove build/.git/objects/20/f36b5326a73789af2ff0e4464a8e80518018c3
remove build/.git/objects/98/ef9fc3abdedb871beba12bf1097e38a4a4cd48
remove build/.git/objects/7d/fde9e9fb6c498760f9c026f77bdaf778aea0a6
remove build/.git/objects/91/33babd8b3722a65e50a5514313aa65ec596019
remove build/.git/logs/refs/heads/master
remove build/.git/logs/HEAD
remove build/.git/hooks/post-update.sample
remove build/.git/hooks/pre-rebase.sample
remove build/.git/hooks/pre-push.sample
remove build/.git/hooks/update.sample
remove build/.git/hooks/pre-applypatch.sample
remove build/.git/hooks/commit-msg.sample
remove build/.git/hooks/applypatch-msg.sample
remove build/.git/hooks/prepare-commit-msg.sample
remove build/.git/hooks/pre-commit.sample
remove build/.git/index
remove build/.git/info/exclude
remove build/.git/config
remove build/.git/refs/heads/master
remove build/.git/description
remove build/.git/COMMIT_EDITMSG
remove build/.git/HEAD
Project built successfully.

Build remove all git files, but not the .git directory.
This inconsistency leads Middleman::Deploy::Strategies::Git::ForcePush::add_remote_url to produce side effects:

def add_remote_url
url = get_remote_url

unless File.exist?('.git')
git init
git remote add origin #{url}
git config user.name "#{user_name}"
git config user.email "#{user_email}"
else
# check if the remote repo has changed
unless url == git config --get remote.origin.url.chop
git remote rm origin
git remote add origin #{url} # <-- Here the root project origin is overwritten!!
end

So .git data of build directory will be removed, origin of root project will be overwritten, and the root project will be pushed instead of builded one.
Infact now in root project git remote -v gives

origin [email protected]:username/username.github.io.git
gh-pages [email protected]:username/username.github.io.git

That's why removing each time the build directory seems to workaround.

In my opinion the build process should preserve the .git directory. Or the method above should do a more complex check process to see if remotes are ok..

@MinasMazar
Copy link

However this implementation of Middleman::Deploy::Strategies::Git::ForcePush::add_remote_url will regenerate .git data every time. Maybe it's a better solution than cleaning the entire build directory.

def add_remote_url
  url = get_remote_url

  `git init`
  `git remote add origin #{url}`
  `git config user.name "#{user_name}"`
  `git config user.email "#{user_email}"`
end

egardner added a commit to egardner/larb-publishing-course that referenced this issue Jan 25, 2016
Borrowing a hotfix extension from this discussion:
karlfreeman/middleman-deploy#114

The problem: for somereason mm-deploy starts deploying the source files
to gh-pages isntead of the built output. This extension forcibly removes
the build dir every time, which seems to solve the problem.
@coreyward
Copy link

The issue isn't with middleman-deploy or git so much as it is with middleman v4 which changed the build process. v4.1.0.rc.2 includes a config directive to change this behavior and resolve the above problem. See middleman/middleman#1716 for the full details.

I don't use middleman-deploy and still had this issue, for what it's worth (I've been using https://github.com/edgecase/middleman-gh-pages successfully for a long while).

configure :deploy do
  set :skip_build_clean do |path|
    path =~ /\.git/
  end
end

@Yanchek99
Copy link

Experiencing the same behavior with my Middleman 4 project.

@jodosha
Copy link

jodosha commented Jan 29, 2016

I used @egardner patch and it worked! Thanks!

@KitaitiMakoto
Copy link

@coreyward 's information solved my Middeman v4.1 project's issue. Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests