git-remote-bzr icon indicating copy to clipboard operation
git-remote-bzr copied to clipboard

Create a new remote bzr branch when it doesn't exist on push

Open dequis opened this issue 11 years ago • 8 comments

When pushing, if the remote bzr branch does not exist, this error appears:

$ git push bzr-dequis bzr-test
Traceback (most recent call last):
  File "/home/dx/bin/git-remote-bzr", line 981, in <module>
    sys.exit(main(sys.argv))
  File "/home/dx/bin/git-remote-bzr", line 967, in main
    do_export(parser)
  File "/home/dx/bin/git-remote-bzr", line 682, in do_export
    branch = get_remote_branch(name)
  File "/home/dx/bin/git-remote-bzr", line 787, in get_remote_branch
    remote_branch = bzrlib.branch.Branch.open(branches[name],
KeyError: 'bzr-test'
error: failed to push some refs to 'bzr::bzr+ssh://dequis.org/home/dx/web/bzr/bitlbee'

I tried patching it, my (failed) attempt is at https://github.com/dequis/git-remote-bzr/commit/7365028f8bd5d3afeceabd20aad1b21f443a98f9 - a bit hacky (getting url from sys.argv[2]) and doesn't really work, other than creating an empty branch that can't get pushed to, while never reporting any errors on "git push":

$ git push bzr-dequis bzr-test
To bzr::bzr+ssh://dequis.org/home/dx/web/bzr/bitlbee
   bf4be5b..bf4be5b  bzr-test -> bzr-test

That short commit hash is my current HEAD commit. It shows this exact same output every time, even if the remote doesn't exist or after running it twice in a row.

The bzr log output in the bzr-test directory in the remote repo is empty.

The bzr log output in .git/bzr/bzr-dequis/clone/bzr-test shows 1046 revisions, the last one being HEAD.

I have no idea what I'm doing.

dequis avatar Sep 22 '14 10:09 dequis

I have a similar problem when I want to contribute to launchpad.

The clone is OK:

$ git clone bzr::lp:ubumirror
Cloning into 'ubumirror'...
Checking connectivity... done.

Now I create a new git branch and makes some changes

$ git checkout -b test master
$ echo "Test file" > test
$ git add test
$ git commit -m "Test commit"

I add my personal not yet existing launchpad repository:

$ git remote add perso bzr::lp:~mylogin/ubumirror
$ git push perso test
Traceback (most recent call last):
  File "/usr/bin/git-remote-bzr", line 1022, in <module>
    sys.exit(main(sys.argv))
  File "/usr/bin/git-remote-bzr", line 994, in main
    repo = get_repo(url, alias)
  File "/usr/bin/git-remote-bzr", line 870, in get_repo
    origin = bzrlib.bzrdir.BzrDir.open(url, possible_transports=transports)
  File "/usr/lib/python2.7/dist-packages/bzrlib/controldir.py", line 687, in open
    t = _mod_transport.get_transport(base, possible_transports)
  File "/usr/lib/python2.7/dist-packages/bzrlib/transport/__init__.py", line 1680, in get_transport
    return get_transport_from_url(location_to_url(base), possible_transports)
  File "/usr/lib/python2.7/dist-packages/bzrlib/transport/__init__.py", line 1602, in location_to_url
    location = directories.dereference(location)
  File "/usr/lib/python2.7/dist-packages/bzrlib/directory_service.py", line 66, in dereference
    return service().look_up(name, url)
  File "/usr/lib/python2.7/dist-packages/bzrlib/plugins/launchpad/lp_directory.py", line 68, in look_up
    return self._resolve(url)
  File "/usr/lib/python2.7/dist-packages/bzrlib/plugins/launchpad/lp_directory.py", line 165, in _resolve
    result = self._resolve_locally(path, url, _request_factory)
  File "/usr/lib/python2.7/dist-packages/bzrlib/plugins/launchpad/lp_directory.py", line 93, in _resolve_locally
    return self._resolve_via_xmlrpc(path, url, _request_factory)
  File "/usr/lib/python2.7/dist-packages/bzrlib/plugins/launchpad/lp_directory.py", line 103, in _resolve_via_xmlrpc
    path=url, extra=fault.faultString)
bzrlib.errors.InvalidURL: Invalid url supplied to transport: "lp:~mylogin/ubumirror": ~mylogin/ubumirror is too short to be a branch name. Try '~<owner>/+junk/<branch>', '~<owner>/<product>/<branch> or '~<owner>/<distribution>/<series>/<sourcepackage>/<branch>'.

baby-gnu avatar Feb 27 '15 13:02 baby-gnu

@baby-gnu in your case it looks like you just set the remote wrong. Instead of git remote add perso bzr::lp:~mylogin/ubumirror, you should do git remote add perso bzr::lp:~mylogin/ubumirror/my-branch-name and that should resolve that specific issue. However then you'll just get bzrlib.errors.NotBranchError: Not a branch: "bzr+ssh://bazaar.launchpad.net/~mylogin/ubumirror/my-branch-name/". unless you create that branch first.

ghost avatar Mar 05 '15 02:03 ghost

@robru thanks for the explanation.

So, if I understand correctly, I can not have one git repository to track several remote bzr branches?

As my remote branch was not created, I used git-bzr-ng which successfully created the remote branch.

To not pollute this issue, I openned #12.

Regards.

baby-gnu avatar Mar 06 '15 08:03 baby-gnu

@baby-gnu. I don't actually know, I wasn't able to get this to work. I've recently tried https://github.com/zyga/git-lp and it seems to work much better with the launchpad workflow.

ghost avatar Mar 06 '15 22:03 ghost

I'm experiencing this as well. I have cloned the Inkscape repository "lp:inkscape" and want to push either to "lp:~inkscape.dev/inkscape/<new_branch_name>" or "lp:~christoffer-holmstedt/inkscape/<new_branch_name>". Adding them as remote and then pushing doesn't work.

If this doesn't work I'm not sure which workflows are supported with the git-remote-bzr helper. I will have to look into this later on.

christofferholmstedt avatar Mar 22 '15 12:03 christofferholmstedt

:+1:

I was just trying to figure out this issue. I would like to push a PR to a launchpad project, but given a remote like:

$ git remote -v
[...]
lp  bzr::lp:~larsks/project/my-test-branch (fetch)
lp  bzr::lp:~larsks/project/my-test-branch (push)

Attempts to push my changes:

$ git push lp master

Result in:

bzrlib.errors.NotBranchError: Not a branch: "bzr+ssh://bazaar.launchpad.net/~larsks/project/my-test-branch/".

I ended up just using the bzr command to clone the remote project, then git format-patch to move my changes over, then bzr push to create the branch and submit my changes...but I wish I could do this directly from git.

Once the remote branch was created I am able to pushand pull without a problem using git-bzr-remote.

larsks avatar Jun 03 '15 17:06 larsks

git-bzr-ng is better in this case where it can create remote branch if it doesn't exist.

khurshid-alam avatar Dec 04 '15 07:12 khurshid-alam

The above commit (supported by preceding ones) will now create a branch when needed on push. As such, the following launchpad workflow is possible using git-remote-bzr:

$ git clone bzr::lp:project
$ git remote add perso bzr::lp:~user/project/feature
$ git push perso master

Note that the remote url will have to contain the full branch name (as also mentioned in earlier comments). Upgrading to latest HEAD in that commit's repo additionally supports the following:

$ git checkout -b feature master
# work on feature
$ git push perso feature:master

While the difference is marginal, it is is slightly cleaner in that the perso remote's single branch is then usually referred to as master.

mnauw avatar Oct 23 '16 11:10 mnauw