diff options
| author | Brenton Leanhardt <bleanhar@redhat.com> | 2008-06-24 10:14:21 -0400 |
|---|---|---|
| committer | Brenton Leanhardt <bleanhar@redhat.com> | 2008-06-24 13:04:21 -0400 |
| commit | f7b5813468d014bef04b6af8aef5841f4eb0ad99 (patch) | |
| tree | 9f46f65d27d700afb0e81dd89b4f63d63e26487b | |
| parent | 88322aeefb4a3573d6f47cc3836f74c2dfb357dc (diff) | |
| download | tools-f7b5813468d014bef04b6af8aef5841f4eb0ad99.tar.gz tools-f7b5813468d014bef04b6af8aef5841f4eb0ad99.tar.xz tools-f7b5813468d014bef04b6af8aef5841f4eb0ad99.zip | |
Adding support for rebase and push --force
This requies a version 1.0.7.1 of the git gem
| -rw-r--r-- | everest-sync/bin/everest-sync | 78 |
1 files changed, 60 insertions, 18 deletions
diff --git a/everest-sync/bin/everest-sync b/everest-sync/bin/everest-sync index 798f781..560a4f5 100644 --- a/everest-sync/bin/everest-sync +++ b/everest-sync/bin/everest-sync @@ -69,12 +69,11 @@ Main { end end - # TODO - #menu.choice "rebase" do - # git_action(git) do |b| - # - # end - #end + menu.choice "rebase" do + git_action(git) do |b| + git.rebase(b) + end + end menu.choice "something even more exciting" do git_action(git) do |b| @@ -102,7 +101,7 @@ Main { if File.directory?(dest) verbose("Push all branches in #{d} to #{dest}") g = Git.open(d) - g.branches.local.each {|b| g.push(dest,b)} + g.branches.local.each {|b| g.push(dest,b, :force => true)} else verbose("Making #{bare_repo_parent_dir}") FileUtils.mkdir_p(bare_repo_parent_dir) @@ -143,8 +142,15 @@ Main { puts msg if params['verbose'].given? end - #I couldn't find a way to 'checkout -b' so this will have to do for now - def checkout_b(git, branch) + # I couldn't find a way to 'checkout -b --force' so this will have to do for + # now. It would be better to work this into the git gem at some point. + def checkout_b(git, branch, opts = {}) + if stale_branch = git.branches.local.find {|b| b.name == branch.name} + verbose("Removing stale branch #{stale_branch}") + stale_branch.delete + end if opts[:force] + + verbose("Setting #{branch.name} to #{git.object(branch).sha}") git.branch(branch.name).checkout git.reset_hard(branch) end @@ -186,6 +192,7 @@ Main { (b.remote.to_s == @everest_repo) && b.name != 'HEAD' end + # Don't bother asking the user for a branch if there is only one if remote_branches.size == 1 git_action_safe(g, remote_branches[0], &block) else @@ -240,28 +247,63 @@ Main { repo_url = "git://#{@everest_repo + repo_path}" # We need to clone from the remote if the local clone doesn't exist - unless File.directory?(clone_dir) + git = if File.directory?(clone_dir) + verbose "Opening #{clone_dir}" + Git.open(clone_dir) + else # NOTE: For symplicity's sake I decided not to bother cloning from /pub/git # locally if the repo does not exist in the working dir. This would # make the tool have to detect if the local clone is out sync. While # this isn't hard, I don't feel like messing with it at the moment. verbose("Cloning #{repo_url} to #{clone_dir}") g = Git.clone(repo_url, clone_dir) + g.branches.remote.each do |r| next if r.name == 'HEAD' checkout_b(g, r) end - else - g = Git.open(clone_dir) - verbose "opened #{clone_dir}" + + # Don't bother asking the user anything else about this repo if we + # don't even have a local public copy yet. + unless File.directory?(repo_path) + verbose("No local public repo found at #{repo_path}") + next + end + + g # value from if + end + + ############################## + # Setup Remotes: + ############################## + + # Don't add the remote if it already exists + # Note: By convention the remote must be the same as the everest repo fqdn + git.add_remote(@everest_repo, repo_url) unless git.remotes.find {|r| r.name == @everest_repo} + verbose("Fetching #{@everest_repo}") + git.fetch(@everest_repo) + + # If we have a public repo make sure we have a remote that points to it + localcache_remote_name = 'localcache' + if File.directory?(repo_path) # This dir will exist if the user has ever used 'save' + # Add a remote if we don't have one + unless git.remotes.find {|r| r.name == localcache_remote_name} + git.add_remote(localcache_remote_name, repo_path) + end - # Don't add the remote if it already exists - # Note: By convention the remote must be the same as the everest repo fqdn - g.add_remote(@everest_repo, repo_url) unless g.remotes.find {|r| r.name == @everest_repo} - g.fetch(@everest_repo) + verbose("Fetching #{localcache_remote_name}") + git.fetch(localcache_remote_name) - yield(g) + # reset hard all our local branches + local_public_branches = git.branches.remote.find_all do |b| + next if b.name == 'HEAD' + b.remote.name == localcache_remote_name + end + + local_public_branches.each {|b| checkout_b(git, b, :force => true)} end + + yield(git) end end |
