fabioz / mu-repo

Tool to help in dealing with multiple git repositories
http://fabioz.github.io/mu-repo/
Other
295 stars 37 forks source link

`mu checkout <branch>` crashes with a stacktrace when the branch is a substring of one that exists #37

Closed tadeu closed 6 years ago

tadeu commented 6 years ago

Here's how to reproduce:

C:\Temp> mkdir mutest

C:\Temp> cd mutest\

C:\Temp\mutest> echo a > a

C:\Temp\mutest> git init
Initialized empty Git repository in C:/Temp/mutest/.git/

C:\Temp\mutest (master)> git add a

C:\Temp\mutest (master)> git commit -m "a"
[master (root-commit) 6b01352] a
 1 file changed, 1 insertion(+)
 create mode 100644 a

C:\Temp\mutest (master)> git checkout -b ab
Switched to a new branch 'ab'

C:\Temp\mutest (ab)> git checkout -b abcd
Switched to a new branch 'abcd'

C:\Temp\mutest (abcd)> git branch
  ab
* abcd
  master

C:\Temp\mutest (abcd)> mu checkout abc
Traceback (most recent call last):
  File "C:\Miniconda\Scripts\mu-script.py", line 5, in <module>
    sys.exit(mu_repo.main_entry_point())
  File "C:\Miniconda\lib\site-packages\mu_repo\__init__.py", line 348, in main_entry_point
    main()
  File "C:\Miniconda\lib\site-packages\mu_repo\__init__.py", line 337, in main
    return Run(Params(config, args, config_file))
  File "C:\Miniconda\lib\site-packages\mu_repo\action_checkout.py", line 27, in Run
    branch, _repo = iteritems(branch_to_repos).next()
AttributeError: 'dict_items' object has no attribute 'next'

I think the problem is with this code (iteritems(branch_to_repos).next()), that fails in Python 3. In Python 3, changing it to next(iter(iteritems(branch_to_repos))) makes it work, but then next would probably have to be added to backwards.

fabioz commented 6 years ago

I think next is ok for both python 2 and 3, so, just doing:

next(iteritems(branch_to_repos))

is ok (without adding it to backwards).