git-ubuntu support for worktrees

Bug #2043815 reported by Sergio Durigan Junior
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
git-ubuntu
Triaged
Medium
Unassigned

Bug Description

I like using worktrees to work on more complex packages, and I've just noticed that "git ubuntu prepare-upload args" doesn't work when inside one.

This is what I see:

 --git-ubuntu-prepare-upload-args-failed
 Traceback (most recent call last):
   File "/snap/git-ubuntu/1332/usr/bin/git-ubuntu", line 11, in <module>
     load_entry_point('gitubuntu==1.1', 'console_scripts', 'git-ubuntu')()
   File "/snap/git-ubuntu/1332/usr/lib/python3/dist-packages/gitubuntu/__main__.py", line 270, in main
    sys.exit(args.func(args))
   File "/snap/git-ubuntu/1332/usr/lib/python3/dist-packages/gitubuntu/prepare_upload.py", line 478, in cli_printargs
     repo = gitubuntu.git_repository.GitUbuntuRepository('.')
   File "/snap/git-ubuntu/1332/usr/lib/python3/dist-packages/gitubuntu/git_repository.py", line 1113, in __init__
     self.raw_repo = pygit2.init_repository(self._local_dir)
   File "/snap/git-ubuntu/1332/usr/lib/python3/dist-packages/pygit2/__init__.py", line 149, in init_repository
     check_error(err)
   File "/snap/git-ubuntu/1332/usr/lib/python3/dist-packages/pygit2/errors.py", line 46, in check_error
     raise ValueError(message)
 ValueError: failed to make directory '/home/sergio/work/qemu/qemu-ibm-lp2003673/.git': directory exists

The problem happens because of how GitUbuntuRepository is initialized:

https://git.launchpad.net/git-ubuntu/tree/gitubuntu/git_repository.py#n1084

            try:
                os.mkdir(local_dir)
            except FileExistsError:
                local_dir_list = os.listdir(local_dir)
                if local_dir_list and os.getenv(
                    'GIT_DIR',
                    '.git',
                ) not in local_dir_list:
                    logging.error('Specified directory %s must either '
                                  'be empty or have been previously '
                                  'imported to.', local_dir)
                    sys.exit(1)

It assumes that ".git" will always be a directory, but inside worktrees ".git" is actually a regular file.

Tags: workflow
Robie Basak (racb)
tags: added: workflow
Changed in git-ubuntu:
status: New → Triaged
importance: Undecided → Medium
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.