Do you want to request a feature or report a bug?
Bug
What is the current behavior?
Branch selection in Add Submodule form is not working properly.
If the current behavior is a bug, please provide the steps to reproduce and if possible a minimal demo of the problem.
1 - Repository men煤 > Submodules
2 - Click "Add submodule" button
3 - Browse to another git repository
4 - Select branch from offered options in combobox.
5 - Click "Add" button
6 - Submodule is not added with error:
"C:\Program Files\Git\bin\git.exe" submodule add -b "refs/heads/master" "C:/Users/jordi/Desktop/Dev/a" "a"
Cloning into 'C:/Users/jordi/Desktop/Dev/b/a'...
done.
fatal: 'origin/refs/heads/master' is not a commit and a branch 'refs/heads/master' cannot be created from it
Unable to checkout submodule 'a'
Done
What is the expected behavior?
Submodule is created from selected repository and selected branch is checked out.
Environment you encounter the issue:
Did this work in previous version of GitExtensions (which)?
Not working either in GitExtensions 2.50.02
After step 6, if you repeat steps from 1 to 5 selecting the same repository and branch, then the submodule is properly added.
Tried issuing on the command line the same commands that Git Extensions issues and the behavior is reproduced:
C:\>mkdir MyRepo
C:\>cd MyRepo
C:\MyRepo>git init
Initialized empty Git repository in C:/MyRepo/.git/
C:\MyRepo>git submodule add -b refs/heads/master C:\MySubmodulesLibrary\MySubmodule MySubmodule
Cloning into 'C:/MyRepo/MySubmodule'...
done.
fatal: 'origin/refs/heads/master' is not a commit and a branch 'refs/heads/master' cannot be created from it
Unable to checkout submodule 'MySubmodule'
C:\MyRepo>git submodule add -b refs/heads/master C:\MySubmodulesLibrary\MySubmodule MySubmodule
Adding existing repo at 'MySubmodule' to the index
warning: LF will be replaced by CRLF in .gitmodules.
The file will have its original line endings in your working directory.
Please see Stack Overflow :: Git submodule add error.
Seems the problem is the git command issued when Add is clicked. -b option should be used with the name of the branch only, putting refs/heads/ in front of the branch name when using this option is causing the error.
When using -b option without refs/heads/ it works the first time:
C:\>mkdir MyRepo
C:\>cd MyRepo
C:\MyRepo>git init
Initialized empty Git repository in C:/MyRepo/.git/
C:\MyRepo>git submodule add -b master C:\MySubmodulesLibrary\MySubmodule MySubmodule
Cloning into 'C:/MyRepo/MySubmodule'...
done.
warning: LF will be replaced by CRLF in .gitmodules.
The file will have its original line endings in your working directory.
Branch is only used when --remote is set for submodule commands, so no use from GE.
One "solution" could be to hide branch too.
Most helpful comment
Branch is only used when --remote is set for submodule commands, so no use from GE.
One "solution" could be to hide branch too.