snoopycrimecop/snoopycrimecop — pull request #22 by joshmoore (2012-12-12 10:39:00+00:00)
Title: Rebase command et al.

This branch has grown quite a lot while implementing the ``rebase`` command. See individual commits for the addition of ``token`` and ``SCC_DEBUG_LEVEL``.

## ``rebase`` ##
After creating a PR like this:
```
@my-work ~/code/scc.git/snoopys-sandbox $ hub pull-request -b openmicroscopy:dev_4_4
https://github.com/openmicroscopy/snoopys-sandbox/pull/14
```

The following command will rebase and open a PR, cleaning up the local branch after it's down:
```
@my-work ~/code/scc.git/snoopys-sandbox $ export SCC_DEBUG_LEVEL=10
@my-work ~/code/scc.git/snoopys-sandbox $ ../scc.py rebase --pr 14 develop
2012-12-12 11:00:28,022 DEBUG [ scc] Found github.token
2012-12-12 11:00:29,901 DEBUG [ scc] Create Github instance identified as joshmoore
2012-12-12 11:00:29,902 INFO [ scc]
2012-12-12 11:00:29,902 DEBUG [ scc] Check current status
2012-12-12 11:00:29,902 DEBUG [ scc] Calling 'git log --oneline -n 1 HEAD'
2012-12-12 11:00:29,909 DEBUG [ scc] 1820b1f work
2012-12-12 11:00:29,909 DEBUG [ scc] Calling 'git submodule status'
2012-12-12 11:00:29,968 DEBUG [ scc] Calling 'git config --get remote.origin.url'
2012-12-12 11:00:29,975 INFO [ scc] Repository: openmicroscopy/snoopys-sandbox
2012-12-12 11:00:29,976 DEBUG [ scc] github.get_user
2012-12-12 11:00:32,328 DEBUG [ scc] github.get_organization
2012-12-12 11:00:33,068 DEBUG [ scc] Register Github repository openmicroscopy/snoopys-sandbox
2012-12-12 11:00:33,068 DEBUG [ scc] Register Git repository /Users/moore/code/scc.git/snoopys-sandbox
2012-12-12 11:00:33,068 DEBUG [ scc] Calling 'git config --get remote.origin.url'
2012-12-12 11:00:33,076 INFO [ scc] Repository: openmicroscopy/snoopys-sandbox
2012-12-12 11:00:33,077 DEBUG [ scc] Get current head
2012-12-12 11:00:33,077 DEBUG [ scc] Calling 'git symbolic-ref HEAD' for stdout/err
2012-12-12 11:00:34,663 INFO [ scc] PR 14: work opened by Josh Moore against dev_4_4
2012-12-12 11:00:34,664 INFO [ scc] Head: 1820b1
2012-12-12 11:00:35,364 INFO [ scc] Merged: False
2012-12-12 11:00:53,837 DEBUG [ scc] Calling 'git rev-list --first-parent 1820b1f65e97e3e5b3e3d01937e20aa7e85e983f'
2012-12-12 11:00:53,846 DEBUG [ scc] Calling 'git rev-list --first-parent origin/dev_4_4'
2012-12-12 11:00:53,850 INFO [ scc] Branching SHA1: 57d965
2012-12-12 11:00:53,851 DEBUG [ scc] Calling 'git rebase --onto origin/develop 57d965 1820b1f65e97e3e5b3e3d01937e20aa7e85e983f'
2012-12-12 11:00:53,938 DEBUG [ scc] First, rewinding head to replay your work on top of it...
2012-12-12 11:00:54,095 DEBUG [ scc] Applying: work
2012-12-12 11:00:54,874 DEBUG [ scc] New branch rebased/develop/my-work from HEAD...
2012-12-12 11:00:54,874 DEBUG [ scc] Calling 'git checkout -b rebased/develop/my-work HEAD'
2012-12-12 11:00:54,895 DEBUG [ scc] Switched to a new branch 'rebased/develop/my-work'
2012-12-12 11:00:54,896 DEBUG [ scc] Pushing branch rebased/develop/my-work to git@github.com:joshmoore/snoopys-sandbox.git...
2012-12-12 11:00:54,896 DEBUG [ scc] Calling 'git push git@github.com:joshmoore/snoopys-sandbox.git rebased/develop/my-work'
2012-12-12 11:01:00,408 DEBUG [ scc] To git@github.com:joshmoore/snoopys-sandbox.git
2012-12-12 11:01:00,410 DEBUG [ scc] github.get_user
2012-12-12 11:01:00,410 DEBUG [ scc] * [new branch] rebased/develop/my-work -> rebased/develop/my-work
2012-12-12 11:01:01,856 DEBUG [ scc] github.get_organization
https://github.com/openmicroscopy/snoopys-sandbox/pull/23
2012-12-12 11:01:04,506 DEBUG [ scc] Checkout branch my-work...
2012-12-12 11:01:04,506 DEBUG [ scc] Calling 'git checkout my-work'
2012-12-12 11:01:04,515 DEBUG [ scc] Switched to branch 'my-work'
2012-12-12 11:01:04,558 DEBUG [ scc] Deleting branch rebased/develop/my-work locally...
2012-12-12 11:01:04,558 DEBUG [ scc] Calling 'git branch -D rebased/develop/my-work'
2012-12-12 11:01:04,566 DEBUG [ scc] Deleted branch rebased/develop/my-work (was c04f815).
```

Without debugging, it looks like this:
```
@my-work ~/code/scc.git/snoopys-sandbox $ ../scc.py rebase --pr 14 develop
# Created local branch rebased/develop/my-work
# Pushed rebased/develop/my-work to git@github.com:joshmoore/snoopys-sandbox.git
https://github.com/openmicroscopy/snoopys-sandbox/pull/23
```

And if the new rebase isn't mergeable it looks like this:
```
@my-work ~/code/scc.git/snoopys-sandbox $ ../scc.py rebase --pr 14 develop
# Created local branch rebased/develop/my-work
# Pushed rebased/develop/my-work to git@github.com:joshmoore/snoopys-sandbox.git
https://github.com/openmicroscopy/snoopys-sandbox/pull/23
#
# WARNING: PR is NOT mergeable!
#
```

Probably several issues along the lines of:
* If a branch is already checked out of the given name then the rebase will fail leaving a temporary commit in place:

```
2012-12-12 10:25:44,347 INFO [ scc] Repository: openmicroscopy/snoopys-sandbox
2012-12-12 10:25:45,154 DEBUG [ scc] New branch rebased/develop/my-work from 1820b1f65e97e3e5b3e3d01937e20aa7e85e983f...
2012-12-12 10:25:45,154 DEBUG [ scc] Calling 'git checkout -b rebased/develop/my-work 1820b1f65e97e3e5b3e3d01937e20aa7e85e983f'
Traceback (most recent call last):
2012-12-12 10:25:45,161 DEBUG [ scc] fatal: A branch named 'rebased/develop/my-work' already exists.
File "../scc.py", line 1159, in
main()
File "../scc.py", line 1155, in main
ns.func(ns)
File "../scc.py", line 1023, in __call__
self.rebase(args, main_repo)
File "../scc.py", line 1056, in rebase
main_repo.new_branch(new_branch, head=pr_head)
File "../scc.py", line 631, in new_branch
self.call("git", "checkout", "-b", name, head)
File "../scc.py", line 540, in call
raise Exception("rc=%s" % rc)
Exception: rc=128
@(8916359...) ~/code/scc.git/snoopys-sandbox $ git branch -a
* (no branch)
```

NB: If you want to get rid of the PR, you only need to then push to the created branch: