Setup a git repository master that points at actual repository
PROJECT_NAME='jsinterop-generator' | |
PROJECT_SLUG='jsinterop-generator' | |
UPSTREAM_OWNER='google' | |
LOCAL_OWNER='realityforge' | |
LOCAL_BRANCHES_TO_KEEP=%w(TravisCiIntegration) | |
#WARNING this will delete local branches which may contain your changes | |
DELETE_LOCAL_BRANCHES=true | |
def mysystem(command, fail_on_error = true) | |
puts "system (#{Dir.pwd}): #{command}" if @verbose | |
system(command) || !fail_on_error || (raise "Error executing #{command} in #{Dir.pwd}") | |
end | |
mysystem("git clone https://github.com/#{LOCAL_OWNER}/#{PROJECT_SLUG}.git") unless File.exist?(PROJECT_SLUG) | |
Dir.chdir PROJECT_SLUG | |
mysystem("git remote add upstream https://github.com/#{UPSTREAM_OWNER}/#{PROJECT_SLUG}.git", false) | |
mysystem("git fetch upstream") | |
mysystem("git checkout upstream/master") | |
mysystem("git branch -f upstream") | |
mysystem("git checkout upstream") | |
mysystem("git push --set-upstream -f origin upstream") | |
if DELETE_LOCAL_BRANCHES | |
`git ls-remote --heads --refs 2>/dev/null`.split("\n").each do |line| | |
if line =~ /^.*refs\/heads\/(.*)$/ | |
head = $1 | |
next if (LOCAL_BRANCHES_TO_KEEP + %w(master upstream)).include?(head) | |
puts "Removing branch #{head}" | |
mysystem("git push origin :#{head}") | |
mysystem("git branch -d #{head}", false) | |
end | |
end | |
end | |
`git ls-remote --tags --refs 2>/dev/null`.split("\n").each do |line| | |
if line =~ /^.*refs\/tags\/(.*)$/ | |
tag = $1 | |
puts "Removing tag #{tag}" | |
mysystem("git push origin :#{tag}") | |
mysystem("git tag -d #{tag}") | |
end | |
end | |
mysystem("git branch -d master", false) | |
mysystem("git checkout --orphan master") | |
mysystem("git rm --cached -r .") | |
mysystem("git add .") | |
mysystem("git reset --hard") | |
IO.write("README.md",<<CONTENT) | |
# Peter Donald's #{PROJECT_NAME} Repository | |
This repository contains feature branches for the upstream repository: [#{PROJECT_NAME}](https://github.com/#{UPSTREAM_OWNER}/#{PROJECT_SLUG}). | |
It doesn not contain a meaningful master branch. | |
CONTENT | |
mysystem("git add -f README.md") | |
mysystem('git commit -m "Add a README that describes the purpose of the repository."') | |
mysystem("git push --set-upstream -f origin master") | |
mysystem("git checkout upstream") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment