Skip to content

Commit

Permalink
Do not assume Git default branch is called "master"
Browse files Browse the repository at this point in the history
Running git init won't always create a "master" branch. More and
more configurations creates a branch named "main", and the name of the
initial branch can be changed using:
    [init]
        defaultBranch = nameofbranch

To get the first branch created by git init, run:

     git branch --show-current
  • Loading branch information
enzbang committed Mar 26, 2024
1 parent 1fe4163 commit cd79be8
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion tests/tests_e3/vcs/git/main_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ def test_git_repo():
repo.git_cmd(["config", "user.email", "[email protected]"])
repo.git_cmd(["config", "user.name", "e3 core"])
repo.git_cmd(["commit", "-m", "new file"])

main_branch = repo.git_cmd(["branch", "--show-current"]).out

repo.git_cmd(["tag", "-a", "-m", "new tag", "20.0855369232"])
repo.git_cmd(["notes", "--ref", "review", "add", "HEAD", "-F", commit_note])

Expand Down Expand Up @@ -130,7 +133,7 @@ def test_git_repo():
repo2 = GitRepository(working_tree2)
giturl = "file://%s" % working_tree.replace("\\", "/")
repo2.init(url=giturl, remote="tree1")
repo2.update(url=giturl, refspec="master")
repo2.update(url=giturl, refspec=main_branch)
assert repo2.rev_parse() == repo.rev_parse()

repo2.fetch_gerrit_notes(url=giturl)
Expand Down

0 comments on commit cd79be8

Please sign in to comment.