-
Notifications
You must be signed in to change notification settings - Fork 899
How to control the name of the default branch from Repository.Init? #1964
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 &ld 8000 quo;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
Comments
You can use the |
Thanks. I couldn't find an API to set config settings before creating a repo. Can you direct me to it? |
Same issue here, seems to be a chicken and egg problem. "Updating |
Would really appreciate this feature! 'init.defaultBranch' is set for me in my only git setup, still libgit2 doesn't seem to listen to it |
Many tests are assuming the default branch is `master`. But if the `~/.gitconfig` file contains another default branch name, then all these tests will fail. ```ini [init] defaultBranch = "main" ``` See [How to control the name of the default branch from Repository.Init?][1] on the LibGit2Sharp repository. [1]: libgit2/libgit2sharp#1964
* Fix running tests on macOS On macOS, the temporary directory contains a symlink and all tests using `DisposableRepository` would fail with the following error: > System.ArgumentException Unable to process file '/var/folders/62/pz7b9x0x7hv54vy47pllqlvw0000gn/T/edic1ukd/.gitignore'. This f 81F8 ile is not located under the working directory of the repository ('/private/var/folders/62/pz7b9x0x7hv54vy47pllqlvw0000gn/T/edic1ukd/'). at LibGit2Sharp.RepositoryExtensions.BuildRelativePathFrom(IRepository repo, String path) in /_/LibGit2Sharp/RepositoryExtensions.cs:line 215 at LibGit2Sharp.Repository.ToFilePaths(IEnumerable`1 paths) in /_/LibGit2Sharp/Repository.cs:line 1676 at LibGit2Sharp.Diff.BuildDiffList(ObjectId oldTreeId, ObjectId newTreeId, TreeComparisonHandleRetriever comparisonHandleRetriever, DiffModifiers diffOptions, IEnumerable`1 paths, ExplicitPathsOptions explicitPathsOptions, CompareOptions compareOptions) in /_/LibGit2Sharp/Diff.cs:line 544 at LibGit2Sharp.Diff.Compare[T](DiffModifiers diffOptions, IEnumerable`1 paths, ExplicitPathsOptions explicitPathsOptions, CompareOptions compareOptions) in /_/LibGit2Sharp/Diff.cs:line 483 at LibGit2Sharp.Commands.Stage(IRepository repository, IEnumerable`1 paths, StageOptions stageOptions) in /_/LibGit2Sharp/Commands/Stage.cs:line 77 at LibGit2Sharp.Commands.Stage(IRepository repository, String path) in /_/LibGit2Sharp/Commands/Stage.cs:line 25 at Incrementalist.Tests.Helpers.DisposableRepository.WriteFile(String fileName, String fileText) in ~/Incrementalist/src/Incrementalist.Tests/Helpers/DisposableRepository.cs:line 131 at Incrementalist.Tests.Helpers.DisposableRepository.Init() in ~/Incrementalist/src/Incrementalist.Tests/Helpers/DisposableRepository.cs:line 93 at Incrementalist.Tests.Helpers.DisposableRepository..ctor(AbsolutePath basePath) in ~/Incrementalist/src/Incrementalist.Tests/Helpers/DisposableRepository.cs:line 56 at Incrementalist.Tests.Helpers.DisposableRepository..ctor() in ~/Incrementalist/src/Incrementalist.Tests/Helpers/DisposableRepository.cs:line 46 at Incrementalist.Tests.Git.GitBranchDetectionSpecs..ctor() in ~/Incrementalist/src/Incrementalist.Tests/Git/GitBranchDetectionSpecs.cs:line 18 at System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly, Boolean wrapExceptions) See also libgit2/libgit2sharp#1945 * Ensure that the default branch is named `master` Many tests are assuming the default branch is `master`. But if the `~/.gitconfig` file contains another default branch name, then all these tests will fail. ```ini [init] defaultBranch = "main" ``` See [How to control the name of the default branch from Repository.Init?][1] on the LibGit2Sharp repository. [1]: libgit2/libgit2sharp#1964
For reference, here's how to translate update HEAD after the fact into code, assuming you want to ensure that the default branch is named if (repository.Refs.Head.TargetIdentifier != "refs/heads/main")
{
// ensure the default branch is named "main", see https://github.com/libgit2/libgit2sharp/issues/1964
var master = repository.CreateBranch("main");
repository.Refs.UpdateTarget(repository.Refs.Head, master.Reference);
} Successfully used here: petabridge/Incrementalist@e871112 |
I have automated test failures due to
Repository.Init(string)
creating repos withmain
as the default branch name instead ofmaster
. How can I control the name of the default branch for a new repository so that my tests pass consistently across machines?I tried using libgit2sharp APIs to create a new branch and deleting the old, but in fact on a brand new repository, there is no branch and no commit, so I guess the default branch is just the name that HEAD will use for a new branch once the first commit is authored. It appears this is stored in
.git/HEAD
. Is there an API to help us rewrite that file, perhaps?The text was updated successfully, but these errors were encountered: