Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pass reference to add_worktree #814

Closed
Richard-Mathie opened this issue Aug 31, 2018 · 8 comments
Closed

pass reference to add_worktree #814

Richard-Mathie opened this issue Aug 31, 2018 · 8 comments
Labels

Comments

@Richard-Mathie
Copy link

repo.add_worktree only has arguments of name and path so it is currently not possible to create a work tree on a specific reference (existing branches, tags ect) and it just creates a new branch name

repo.listall_branches()
>>  ['master',
     'develop',
     'foo']

worktree_dir = tempfile.mkdtemp()
os.rmdir(worktree_dir)
worktree_name = 'foo'
worktree = repo.add_worktree(worktree_name, worktree_dir)
>>  Traceback (most recent call last):

      File "<ipython-input-134-cb34d9dc7f6a>", line 4, in <module>
        worktree = repo.add_worktree(worktree_name, worktree_dir)

    ValueError: failed to write reference 'refs/heads/foo': a reference with that name already exists.

my current workaround is to move the reference after the fact but this will still create the unwanted branch, and may leave files in the directory.

branch = repo.branches[name]
branch.set_target(repo.branches[the_branch_i_wanted].target)
# or
branch.set_target(repo.references[some reference].target)
@Richard-Mathie
Copy link
Author

further more we get a segfault on doing this on a bare repo ...

>>> import pygit2
>>> repo = pygit2.init_repository('./bare_repo', True)
>>> repo.list_worktrees()
    []
>>> tree =repo.TreeBuilder().write()
>>> commit_id = repo.create_commit('refs/heads/master',
         repo.default_signature, repo.default_signature, "first commit", tree, [])
>>> repo.branches.create('develop', repo[commit_id])
>>> repo.list_worktrees()
    []
>>> repo.listall_branches()
    ['develop', 'master']

in bash on the repo

$ cd bare_repo
$ git branch 
      develop
    * master
$ git worktree add ../versions/develop develop
Preparing ../versions/bare/develop (identifier develop)
    HEAD is now at 4532215 first commit
$ git worktree list
    /..../bare_repo              (bare)
    /..../../versions/develop  4532215 [develop]

back in python

>>> repo.list_worktrees()
    ['develop']
>>> repo.lookup_worktree('develop')
    Segmentation fault (core dumped)

Any idea why?

@jdavid
Copy link
Member

jdavid commented Sep 6, 2018

We just wrap git_worktree_add, so this looks more like a feature request first for libgit2, as it lacks the commit-ish optional parameter in git worktree add, see https://libgit2.org/libgit2/#HEAD/group/worktree/git_worktree_add . Maybe open an issue in libgit2?

For the segfault, will check later.

@jdavid
Copy link
Member

jdavid commented Sep 8, 2018

Reproduced, I can tell you the segfault happens in the call to git_worktree_lookup, so it seems a libgit2 issue, cc @carlosmn

@jdavid
Copy link
Member

jdavid commented Sep 9, 2018

This is how to prepare the repo without using pygit2:

$ git init --bare bare
$ git --git-dir=bare update-ref refs/heads/develop `echo first | git --git-dir=bare commit-tree 4b825dc642cb6eb9a060e54bf8d69288fbee4904`
$ git --git-dir=bare worktree add versions/develop develop
$ python -c "import pygit2; pygit2.Repository('bare').lookup_worktree('develop')"
Segmentation fault (core dumped)

It should be simple to write a C program that shows the segfault, without pygit2 involved.

@jdavid
Copy link
Member

jdavid commented Oct 6, 2018

Update:

  1. The bug is still present in the latest version of libgit2. Wait for v0.27.6 or v0.28.0 to be released and check again

  2. Apparently the feature is already provided by libgit2, but not documented, feature request git_worktree_add commitish reference libgit2#4823 (comment) @Richard-Mathie PR?

@jdavid
Copy link
Member

jdavid commented Oct 28, 2018

The bug has been fixed in libgit2 0.27.7

So only the feature remains to do, @Richard-Mathie PR?

@Richard-Mathie
Copy link
Author

ill have a look
😄

@jdavid
Copy link
Member

jdavid commented Mar 19, 2019

Done with PR #889

@jdavid jdavid closed this as completed Mar 19, 2019
netbsd-srcmastr referenced this issue in NetBSD/pkgsrc Mar 20, 2019
Add test target.

0.28.0 (2019-03-19)
-------------------------

- Upgrade to libgit2 0.28
  `#878 <https://github.com/libgit2/pygit2/issues/878>`_

- Add binary wheels for Linux
  `#793 <https://github.com/libgit2/pygit2/issues/793>`_
  `#869 <https://github.com/libgit2/pygit2/pull/869>`_
  `#874 <https://github.com/libgit2/pygit2/pull/874>`_
  `#875 <https://github.com/libgit2/pygit2/pull/875>`_
  `#883 <https://github.com/libgit2/pygit2/pull/883>`_

- New ``pygit2.Mailmap``, see documentation
  `#804 <https://github.com/libgit2/pygit2/pull/804>`_

- New ``Repository.apply(...)`` wraps ``git_apply(..)``
  `#841 <https://github.com/libgit2/pygit2/issues/841>`_
  `#843 <https://github.com/libgit2/pygit2/pull/843>`_

- Now ``Repository.merge_analysis(...)`` accepts an optional reference parameter
  `#888 <https://github.com/libgit2/pygit2/pull/888>`_
  `#891 <https://github.com/libgit2/pygit2/pull/891>`_

- Now ``Repository.add_worktree(...)`` accepts an optional reference parameter
  `#814 <https://github.com/libgit2/pygit2/issues/814>`_
  `#889 <https://github.com/libgit2/pygit2/pull/889>`_

- Now it's possible to set SSL certificate locations
  `#876 <https://github.com/libgit2/pygit2/issues/876>`_
  `#879 <https://github.com/libgit2/pygit2/pull/879>`_
  `#884 <https://github.com/libgit2/pygit2/pull/884>`_
  `#886 <https://github.com/libgit2/pygit2/pull/886>`_

- Test and documentation improvements
  `#873 <https://github.com/libgit2/pygit2/pull/873>`_
  `#887 <https://github.com/libgit2/pygit2/pull/887>`_

Breaking changes:

- Now ``worktree.path`` returns the path to the worktree directory, not to the
  `.git` file within
  `#803 <https://github.com/libgit2/pygit2/issues/803>`_

- Remove undocumented ``worktree.git_path``
  `#803 <https://github.com/libgit2/pygit2/issues/803>`_


0.27.4 (2019-01-19)
-------------------------

- New ``pygit2.LIBGIT2_VER`` tuple
  `#845 <https://github.com/libgit2/pygit2/issues/845>`_
  `#848 <https://github.com/libgit2/pygit2/pull/848>`_

- New objects now support (in)equality comparison and hash
  `#852 <https://github.com/libgit2/pygit2/issues/852>`_
  `#853 <https://github.com/libgit2/pygit2/pull/853>`_

- New references now support (in)equality comparison
  `#860 <https://github.com/libgit2/pygit2/issues/860>`_
  `#862 <https://github.com/libgit2/pygit2/pull/862>`_

- New ``paths`` optional argument in ``Repository.checkout()``
  `#858 <https://github.com/libgit2/pygit2/issues/858>`_
  `#859 <https://github.com/libgit2/pygit2/pull/859>`_

- Fix speed and windows package regression
  `#849 <https://github.com/libgit2/pygit2/issues/849>`_
  `#857 <https://github.com/libgit2/pygit2/issues/857>`_
  `#851 <https://github.com/libgit2/pygit2/pull/851>`_

- Fix deprecation warning
  `#850 <https://github.com/libgit2/pygit2/pull/850>`_

- Documentation fixes
  `#855 <https://github.com/libgit2/pygit2/pull/855>`_

- Add Python classifiers to setup.py
  `#861 <https://github.com/libgit2/pygit2/pull/861>`_

- Speeding up tests in Travis
  `#854 <https://github.com/libgit2/pygit2/pull/854>`_

Breaking changes:

- Remove deprecated `Reference.get_object()`, use `Reference.peel()` instead


0.27.3 (2018-12-15)
-------------------------

- Move to pytest, drop support for Python 3.3 and cffi 0.x
  `#824 <https://github.com/libgit2/pygit2/issues/824>`_
  `#826 <https://github.com/libgit2/pygit2/pull/826>`_
  `#833 <https://github.com/libgit2/pygit2/pull/833>`_
  `#834 <https://github.com/libgit2/pygit2/pull/834>`_

- New support comparing signatures for (in)equality

- New ``Submodule.head_id``
  `#817 <https://github.com/libgit2/pygit2/pull/817>`_

- New ``Remote.prune(...)``
  `#825 <https://github.com/libgit2/pygit2/pull/825>`_

- New ``pygit2.reference_is_valid_name(...)``
  `#827 <https://github.com/libgit2/pygit2/pull/827>`_

- New ``AlreadyExistsError`` and ``InvalidSpecError``
  `#828 <https://github.com/libgit2/pygit2/issues/828>`_
  `#829 <https://github.com/libgit2/pygit2/pull/829>`_

- New ``Reference.raw_name``, ``Reference.raw_shorthand``, ``Tag.raw_name``,
  ``Tag.raw_message`` and ``DiffFile.raw_path``
  `#840 <https://github.com/libgit2/pygit2/pull/840>`_

- Fix decode error in commit messages and signatures
  `#839 <https://github.com/libgit2/pygit2/issues/839>`_

- Fix, raise error in ``Repository.descendant_of(...)`` if commit doesn't exist
  `#822 <https://github.com/libgit2/pygit2/issues/822>`_
  `#842 <https://github.com/libgit2/pygit2/pull/842>`_

- Documentation fixes
  `#821 <https://github.com/libgit2/pygit2/pull/821>`_

Breaking changes:

- Remove undocumented ``Tag._message``, replaced by ``Tag.raw_message``
EnTeQuAk referenced this issue in mozilla/addons-server Mar 25, 2019
This PR updates [pygit2](https://pypi.org/project/pygit2) from **0.27.4** to **0.28.0**.



<details>
  <summary>Changelog</summary>
  
  
   ### 0.28.0
   ```
   -------------------------

- Upgrade to libgit2 0.28
  `878 &lt;https://github.com/libgit2/pygit2/issues/878&gt;`_

- Add binary wheels for Linux
  `793 &lt;https://github.com/libgit2/pygit2/issues/793&gt;`_
  `869 &lt;https://github.com/libgit2/pygit2/pull/869&gt;`_
  `874 &lt;https://github.com/libgit2/pygit2/pull/874&gt;`_
  `875 &lt;https://github.com/libgit2/pygit2/pull/875&gt;`_
  `883 &lt;https://github.com/libgit2/pygit2/pull/883&gt;`_

- New ``pygit2.Mailmap``, see documentation
  `804 &lt;https://github.com/libgit2/pygit2/pull/804&gt;`_

- New ``Repository.apply(...)`` wraps ``git_apply(..)``
  `841 &lt;https://github.com/libgit2/pygit2/issues/841&gt;`_
  `843 &lt;https://github.com/libgit2/pygit2/pull/843&gt;`_

- Now ``Repository.merge_analysis(...)`` accepts an optional reference parameter
  `888 &lt;https://github.com/libgit2/pygit2/pull/888&gt;`_
  `891 &lt;https://github.com/libgit2/pygit2/pull/891&gt;`_

- Now ``Repository.add_worktree(...)`` accepts an optional reference parameter
  `814 &lt;https://github.com/libgit2/pygit2/issues/814&gt;`_
  `889 &lt;https://github.com/libgit2/pygit2/pull/889&gt;`_

- Now it&#39;s possible to set SSL certificate locations
  `876 &lt;https://github.com/libgit2/pygit2/issues/876&gt;`_
  `879 &lt;https://github.com/libgit2/pygit2/pull/879&gt;`_
  `884 &lt;https://github.com/libgit2/pygit2/pull/884&gt;`_
  `886 &lt;https://github.com/libgit2/pygit2/pull/886&gt;`_

- Test and documentation improvements
  `873 &lt;https://github.com/libgit2/pygit2/pull/873&gt;`_
  `887 &lt;https://github.com/libgit2/pygit2/pull/887&gt;`_

Breaking changes:

- Now ``worktree.path`` returns the path to the worktree directory, not to the
  `.git` file within
  `803 &lt;https://github.com/libgit2/pygit2/issues/803&gt;`_

- Remove undocumented ``worktree.git_path``
  `803 &lt;https://github.com/libgit2/pygit2/issues/803&gt;`_
   ```
   
  
</details>


 

<details>
  <summary>Links</summary>
  
  - PyPI: https://pypi.org/project/pygit2
  - Changelog: https://pyup.io/changelogs/pygit2/
  - Repo: http://github.com/libgit2/pygit2
</details>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants