Templates doubts: post-install note and not keeping the git history?

I created a template and I was wondering about two things:

  • Is there a way to not bring the git history?

For now I’m cloning with --depth=1 and then running a rm -rf project/.git, but seems a bit messy. Of course, the idea of a template is having it’s own history. Anyway, I guess this is a git issue more than a MiddleMan one, but maybe someone else has some insight about?

  • Is there a way to add some sort of post-install note?

For example I use bower, it would be great if at the end of the middleman init --template=blablaba it could print some sort of:

remember to run bower install! (for ie)

I have been looking to other templates but no one seems to tackle these doubts.

1 Like

I have a similar question as I have build my own template for middleman but don’t want the .git folder created in a new project. Would be nice if it is possible to exclude some directories (or files) from project template generating.

1 Like

Same here! When I create a news project based on my template, it gets all the git commit history and also the remote repo I use to work on my template.

Is there a way to not bring the git history and the git remote tracking branch?

I had the same question / observation.

It’s nice that we can store git clones of middleman template repos in ~/.middleman/, but it’s annoying to have the history of said repo brought along when running middleman init -T my_template.

I did some spelunking and found a way to fix it. Long story short: passing an exclude_pattern for the files in .git to the directory method (part of Thor) will prevent the git cruft from making into your newly init'd dir.

Here is my tweaked version of the build_scaffold! method, found in middleman-core/lib/middleman-core/templates/local.rb:

def build_scaffold!
  directory options[:template].to_s, location,
  	force: options[:force],
  	exclude_pattern: /\.git\/.*/
end

My fix seems reasonable, to me at least, so I’ve opened a PR for it. Here’s hoping to it being accepted!

FWIW, here’s some of the interesting bits I found:

Those are the relevant parts, anyway. Hope that helps.

1 Like

update: the PR i submitted was just merged to v3-stable. (thanks, @tdreyno!) so i’d expect that the next minor point release (3.3.8?) will contain this fix. enjoy!

Awesome @worksperfectly!!! Thanks a lot :slight_smile: