Browse files

Merge pull request #5 from jaked/master

--git option to track generated files in scala-bootstrapper branch
  • Loading branch information...
2 parents 191f930 + 8aac5ff commit 02c3854f1fadc745a8fc683022aee93d970d6b4a Kyle Maxwell committed Jun 1, 2011
Showing with 60 additions and 13 deletions.
  1. +30 −0 README.rdoc
  2. +30 −13 bin/scala-bootstrapper
@@ -15,3 +15,33 @@ Usage:
:$ less
+== Git support
+You can track files generated by scala-bootstrapper in a Git branch,
+and later merge changes from the branch (e.g. to rename a project, or
+to upgrade to a newer version of scala-bootstrapper.
+To get started:
+ :$ scala-bootstrapper --git foo
+For a brand-new project (no <tt>.git</tt> directory) this will
+initialize a Git repo in the directory, generate files into the
+<tt>scala-bootstrapper</tt> branch, and merge the branch to
+For an existing project, this will generate files into the
+<tt>scala-bootstrapper</tt> branch, and merge it to the current branch
+*without* actually taking the changes (just making
+<tt>scala-bootstrapper</tt> a parent of the current branch to anchor
+future merges). This is to avoid clobbering files if you had
+previously run <tt>scala-bootstrapper</tt> without the <tt>--git</tt>
+option (or created files some other way). If you want to merge the
+changes and manually resolve any conflicts, do
+ :$ git cherry-pick --no-commit scala-bootstrapper
+Once the <tt>scala-bootstrapper</tt> branch is created, subsequent
+runs will generate files into the branch and merge it to the current
+branch; if there are conflicts you can resolve them in the usual way.
@@ -43,8 +43,8 @@ def gsub_birds(haystack, name, namespace)
gsub("birdName", name.camelize)
-def sys(cmd)
- system(cmd) || abort("failed: #{cmd}")
+def sys(cmd, abort_on_fail=true)
+ system(cmd + " &> /dev/null") || abort_on_fail && abort("failed: #{cmd}")
require "erb"
@@ -58,30 +58,28 @@ git = opts[:git]
$overwrite_all = true if git
$ex_post_facto = false
$branch = 'master'
+$files = []
if git
if !File.exists?('.git')
if `ls -l` != ''
abort('files in directory, no git repo.')
sys('git init')
- sys("echo 'Project #{project_name}' > README")
+ sys('touch')
sys('git add .')
sys("git commit -m'first commit'")
sys('git checkout -b scala-bootstrapper')
- if `git ls-files -mdo` != ''
- abort('uncommitted files in directory')
+ if `git status -s` != ''
+ abort('uncommitted files in directory.')
$branch = `git branch`.grep(/^\*/).first.chomp.gsub(/^\* (.+)$/, '\1')
- if !system('git checkout scala-bootstrapper')
+ if !sys('git checkout scala-bootstrapper', false)
$ex_post_facto = true
sys('git checkout -b scala-bootstrapper')
- # clean out any existing files on branch
- sys('rm .git/index')
- sys('git clean -fdx')
@@ -108,19 +106,22 @@ Dir["#{root}/**/*"].select{|path| File.file?(path)}.each do |path|
puts "writing #{target_path}"
mkdir_p(File.dirname(target_path)), "w") {|f| f.print(gsub_birds(template.result(binding), project_name, namespace)) }
+ $files << target_path
if File.exists?("src/scripts/")
- `mv src/scripts/ src/scripts/#{project_name.downcase}.sh`
+ startup = "src/scripts/#{project_name.downcase}.sh"
+ `mv src/scripts/ #{startup}`
+ $files << startup
[ "src/scripts/#{project_name.downcase}.sh", "src/scripts/console", "run" ].each do |executable|
`chmod +x #{executable}` if File.exists?(executable)
if git
- sys('git add .')
- system("git commit -m'scala-bootstrapper'") # fails if no change
+ $files.each { |file| sys("git add #{file}") if File.exists?(file) }
+ sys("git commit -m'scala-bootstrapper'", false) # fails if no change
sys("git checkout #{$branch}")
sys('git merge --no-ff --no-commit scala-bootstrapper')
@@ -131,5 +132,21 @@ if git
sys('git clean -fdx')
- system("git commit -m'merged scala-bootstrapper'") # fails if no change
+ sys("git commit -m'merged scala-bootstrapper'", false) # fails if no change
+if $ex_post_facto
+ puts <<EOF
+Found existing .git directory; scala-bootstrapper branch created but
+generated files not merged to #{$branch}. To manually merge changes,
+ git cherry-pick --no-commit scala-bootstrapper
+ git commit
+once you have resolved any conflicts.

0 comments on commit 02c3854

Please sign in to comment.