Skip to content
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 “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

chore: explicitly git init with the master branch in tests requiring it #589

Merged
merged 2 commits into from
Feb 28, 2024

Conversation

nathanwn
Copy link
Member

@nathanwn nathanwn commented Jan 3, 2024

Improves a unit test that fails on my machine.

The test fails due to the assumption that git init always initializes a repo with the branch master. Meanwhile, the git defaultBranch configured on my machine is not master. I think this git config is quite common since GitHub now defaults to main as the main branch.

I also reckon if the test is based on the precondition of "the repo should have a master branch", then it'd better be stated explicitly. This fix tries to achieve that.

Signed-off-by: Nathan Nguyen <nathan.nguyen@oracle.com>
@oracle-contributor-agreement oracle-contributor-agreement bot added the OCA Verified All contributors have signed the Oracle Contributor Agreement. label Jan 3, 2024
@nathanwn nathanwn marked this pull request as ready for review January 3, 2024 14:34
@nathanwn nathanwn self-assigned this Jan 3, 2024
@benmss
Copy link
Member

benmss commented Jan 4, 2024

This is an interesting failure case. However, reliance on branch information in the commit finder (and tests) will be removed in PR #586. When that is merged (without major changes), I think this PR can be closed.

@nathanwn
Copy link
Member Author

nathanwn commented Jan 8, 2024

Given the changes in #586, I will close this PR for now.

@nathanwn nathanwn closed this Jan 8, 2024
@nathanwn nathanwn deleted the nathanwn/fix_tests_checking_out_master branch January 8, 2024 05:44
@nathanwn nathanwn restored the nathanwn/fix_tests_checking_out_master branch February 22, 2024 05:30
@nathanwn
Copy link
Member Author

I still get this error on my side. I don't think the change made in #586 solved the issue.

The result of the test case:

FAILED tests/repo_finder/test_commit_finder.py::test_commit_finder - AttributeError: 'IterableList' object has no attribute 'master'

Here is the line causing the issue:

tree = git_obj.repo.heads.master.commit.tree
.

To reproduce:

  • Add the following to your ~/.gitconfig file:
[init]
    defaultBranch = main
  • Remove the mock repository used in the test:
rm -rf ./tests/repo_finder/mock_repos/commit_finder/sample_repo
  • Re-run the test.

As I have mentioned in the initial PR description, this is not an uncommon config, especially since it is in line with GitHub's default branch naming practice. On the other hand, I don't see why we don't want to explicitly initiate the test repo under the exact condition that the test relies on.

@nathanwn nathanwn reopened this Feb 22, 2024
@tromai
Copy link
Member

tromai commented Feb 23, 2024

I had a look at the initial-branch option for git init here. It is mentioned that the default branch name master is subject to change in the future. Therefore, I think it makes sense not to assume that the default branch for a newly initiated repository is always master.
And I agree that we need to ensure the environment is as expected before the test is run.

Copy link
Member

@tromai tromai left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the changes. I have requested some changes on the documentation of the initiate_repo method.

Signed-off-by: Nathan Nguyen <nathan.nguyen@oracle.com>
Copy link
Member

@tromai tromai left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the changes. LGTM.

@nathanwn nathanwn changed the title chore: explicity git init with the master branch in tests requiring it chore: explicitly git init with the master branch in tests requiring it Feb 28, 2024
@nathanwn nathanwn merged commit 920c035 into staging Feb 28, 2024
13 checks passed
@nathanwn nathanwn deleted the nathanwn/fix_tests_checking_out_master branch February 28, 2024 02:29
art1f1c3R pushed a commit that referenced this pull request Nov 29, 2024
…g it (#589)

Signed-off-by: Nathan Nguyen <nathan.nguyen@oracle.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
OCA Verified All contributors have signed the Oracle Contributor Agreement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants