git: slash-friendly strip of branch name
Review Request #1522 — Created April 21, 2010 and submitted
git branch names can contains slashes, so stripping of everything up to the last slash can break tracking branch detection. This patch introduces a bit friendlier re.sub(r'^refs/heads/', '', ...) This change can be also pulled from github: http://github.com/che0/rbtools/tree/branches-with-slashes2
I developed a test case to pass with branch "mybranch", for which it passed. Switching test branch name to "my/branch" made it fail. Second commit which introduces slash-friendly stripping method makes it pass again.
- Change Summary:
-
Introducing a test case and a bit less repetition.
- Description:
-
git branch names can contains slashes, so stripping of everything up to the last slash can break tracking branch detection. This patch introduces a bit friendlier re.sub(r'^refs/heads/', '', ...)
~ This one-line change can be also pulled from github: http://github.com/che0/rbtools/tree/branches-with-slashes
~ This change can be also pulled from github: http://github.com/che0/rbtools/tree/branches-with-slashes2
- Testing Done:
-
~ Default upstream is origin/master, so to test this behavior we need to have branches with merge set to some other remote branch.
~ I developed a test case to pass with branch "mybranch", for which it passed. Switching test branch name to "my/branch" made it fail. Second commit which introduces slash-friendly stripping method makes it pass again.
- - Then with current master, we get:
- che@nok ~/ipcorder/opengit/rbtools/rbtools $ git checkout fffff1 - Switched to branch 'fffff1' - che@nok ~/ipcorder/opengit/rbtools/rbtools $ post-review -nd - (...) - >>> git config --get branch.fffff1.merge - >>> git config --get branch.fffff1.remote - >>> git config remote.origin.url - >>> repository info: Path: git://github.com/reviewboard/rbtools.git, Base path: , Supports changesets: False - >>> git merge-base origin/fooo refs/heads/fffff1 - (seems ok) - - che@nok ~/ipcorder/opengit/rbtools/rbtools $ git checkout fffff/two
- Switched to branch 'fffff/two'
- che@nok ~/ipcorder/opengit/rbtools/rbtools $ post-review -nd
- (...)
- >>> git config --get branch.two.merge
- >>> git config --get branch.two.remote
- (wrong branch name...)
- >>> git config remote.origin.url
- >>> repository info: Path: git://github.com/reviewboard/rbtools.git, Base path: , Supports changesets: False
- >>> git merge-base origin/master refs/heads/fffff/two
- (ended up with origin/master instead of configured upstream branch)
- - - With the patch:
- che@nok ~/ipcorder/opengit/rbtools/rbtools $ post-review -nd - (...) - >>> git config --get branch.fffff/two.merge - >>> git config --get branch.fffff/two.remote - >>> git config remote.origin.url - >>> repository info: Path: git://github.com/reviewboard/rbtools.git, Base path: , Supports changesets: False - >>> git merge-base origin/fooo refs/heads/fffff/two - (seems to work fine now) - Diff:
-
Revision 2 (+32 -6)