Skip to content
This repository has been archived by the owner on Sep 18, 2021. It is now read-only.

--git option to track generated files in scala-bootstrapper branch #5

Merged
merged 10 commits into from Jun 1, 2011
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
30 changes: 30 additions & 0 deletions README.rdoc
Expand Up @@ -15,3 +15,33 @@ Usage:
Tutorial: Tutorial:


:$ less TUTORIAL.md :$ less TUTORIAL.md

== 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
<tt>master</tt>.

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 changes: 30 additions & 13 deletions bin/scala-bootstrapper
Expand Up @@ -43,8 +43,8 @@ def gsub_birds(haystack, name, namespace)
gsub("birdName", name.camelize) gsub("birdName", name.camelize)
end end


def sys(cmd) def sys(cmd, abort_on_fail=true)
system(cmd) || abort("failed: #{cmd}") system(cmd + " &> /dev/null") || abort_on_fail && abort("failed: #{cmd}")
end end


require "erb" require "erb"
Expand All @@ -58,30 +58,28 @@ git = opts[:git]
$overwrite_all = true if git $overwrite_all = true if git
$ex_post_facto = false $ex_post_facto = false
$branch = 'master' $branch = 'master'
$files = []


if git if git
if !File.exists?('.git') if !File.exists?('.git')
if `ls -l` != '' if `ls -l` != ''
abort('files in directory, no git repo.') abort('files in directory, no git repo.')
end end
sys('git init') sys('git init')
sys("echo 'Project #{project_name}' > README") sys('touch README.md')
sys('git add .') sys('git add .')
sys("git commit -m'first commit'") sys("git commit -m'first commit'")
sys('git checkout -b scala-bootstrapper') sys('git checkout -b scala-bootstrapper')


else else
if `git ls-files -mdo` != '' if `git status -s` != ''
abort('uncommitted files in directory') abort('uncommitted files in directory.')
end end
$branch = `git branch`.grep(/^\*/).first.chomp.gsub(/^\* (.+)$/, '\1') $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 $ex_post_facto = true
sys('git checkout -b scala-bootstrapper') sys('git checkout -b scala-bootstrapper')
# clean out any existing files on branch
sys('rm .git/index')
sys('git clean -fdx')
end end
end end
end end
Expand All @@ -108,19 +106,22 @@ Dir["#{root}/**/*"].select{|path| File.file?(path)}.each do |path|
puts "writing #{target_path}" puts "writing #{target_path}"
mkdir_p(File.dirname(target_path)) mkdir_p(File.dirname(target_path))
File.open(target_path, "w") {|f| f.print(gsub_birds(template.result(binding), project_name, namespace)) } File.open(target_path, "w") {|f| f.print(gsub_birds(template.result(binding), project_name, namespace)) }
$files << target_path
end end


if File.exists?("src/scripts/startup.sh") if File.exists?("src/scripts/startup.sh")
`mv src/scripts/startup.sh src/scripts/#{project_name.downcase}.sh` startup = "src/scripts/#{project_name.downcase}.sh"
`mv src/scripts/startup.sh #{startup}`
$files << startup
end end


[ "src/scripts/#{project_name.downcase}.sh", "src/scripts/console", "run" ].each do |executable| [ "src/scripts/#{project_name.downcase}.sh", "src/scripts/console", "run" ].each do |executable|
`chmod +x #{executable}` if File.exists?(executable) `chmod +x #{executable}` if File.exists?(executable)
end end


if git if git
sys('git add .') $files.each { |file| sys("git add #{file}") if File.exists?(file) }
system("git commit -m'scala-bootstrapper'") # fails if no change sys("git commit -m'scala-bootstrapper'", false) # fails if no change
sys("git checkout #{$branch}") sys("git checkout #{$branch}")
sys('git merge --no-ff --no-commit scala-bootstrapper') sys('git merge --no-ff --no-commit scala-bootstrapper')


Expand All @@ -131,5 +132,21 @@ if git
sys('git clean -fdx') sys('git clean -fdx')
end end


system("git commit -m'merged scala-bootstrapper'") # fails if no change sys("git commit -m'merged scala-bootstrapper'", false) # fails if no change
end

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,
run

git cherry-pick --no-commit scala-bootstrapper

then

git commit

once you have resolved any conflicts.
EOF
end end