Skip to content

Instantly share code, notes, and snippets.

@miio
Created October 30, 2012 17:08
Show Gist options
  • Save miio/3981577 to your computer and use it in GitHub Desktop.
Save miio/3981577 to your computer and use it in GitHub Desktop.
user_name = "miio"
remote_addr = "[email protected]:miio/grit_test.git"
clone_args = {quiet: false, verbose: true, progress: true, branch: 'master'}
# Open Repository
central = create_or_open './storage/central/miio/grit_test/', remote_addr, clone_args
working = create_or_open './storage/working/miio/grit_test/', './storage/central/miio/grit_test/', clone_args
# Add Remote Branch
begin
#central.git.add_remote(user_name.to_sym, './storage/working/miio/grit_test/')
Dir.chdir(central.working_dir) { system("git remote add #{user_name} ../../../working/miio/grit_test") }
Dir.chdir(central.working_dir) { system("git fetch #{user_name}") }
rescue
end
# Refresh Repository
# central.git.pull
working.git.pull
# Append File(Uploaded Test)
filename = 'test1.txt'
filepath = './storage/working/miio/grit_test/' + filename
File.open(filepath, 'ab+') { |f| f << 'Committed using Grit' }
# git add & git commit!
blob = Grit::Blob.create(
working, { name: filename, data: File.read(filepath) }
)
Dir.chdir(working.working_dir) { working.add(blob.name) }
working.commit_index('Added the new text file using Grit!')
working.git.pull
working_branches = central.branches.select { |branch| /ready_working_*/ !~ branch.to_s }
# Create Ready Working Branch
reception_branch = "ready_working_#{Time.now.to_i}"
Dir.chdir(central.working_dir) { system("git checkout -b #{reception_branch} master") }
# Rebase from reception topic branches
working_branches.each do |branch|
begin
Dir.chdir(central.working_dir) { system("git fetch #{user_name}") }
Dir.chdir(central.working_dir) { system("git rebase #{user_name}/master #{reception_branch}") }
rescue
system("git rebase --abort")
#branch.delete
end
end
# TODO: if github create pull request
# push into remote repository
Dir.chdir(central.working_dir) { system("git push origin #{reception_branch}:master") }
Dir.chdir(central.working_dir) { system("git checkout master") }
Dir.chdir(central.working_dir) { system("git branch -D #{reception_branch}") }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment