Skip to content

Add username/email to bare git config in repo #65392

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

Merged

Conversation

justice-adams-apple
Copy link
Contributor

Add a fake git username/password to the update_checkout tests so they don't fail in differently configured git environments. Currently if a user doesn't have a global email/username setup in their git config the tests will fail with

*** Please tell me who you are.

Run

  git config --global user.email "[email protected]"
  git config --global user.name "Your Name"

to set your account's default identity.
Omit --global to set the identity only in this repository.

This PR sets the config for the local mock repository accordingly and ensures that the test is self contained and doesn't rely on the end-users global git environment

Comment on lines 121 to 124
call_quietly(['git', 'config', 'user.name', 'apple_test'],
cwd=local_repo_path)
call_quietly(['git', 'config', 'user.email', '[email protected]'],
cwd=local_repo_path)
Copy link
Member

Choose a reason for hiding this comment

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

Will this overwrite local config for the user?

Copy link
Member

Choose a reason for hiding this comment

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

Also, prefer not using apple. Maybe we can use swift_test and [email protected]

Copy link
Contributor

Choose a reason for hiding this comment

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

Will this overwrite local config for the user?

Yes

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Will this overwrite local config for the user?

This should only update the configuration for the git repository which is created as part of this test unless I'm misunderstanding. From the git config documentation

When writing, the new value is written to the repository local configuration file by default, and options --system, --global, --worktree, --file can be used to tell the command to write to that location (you can say --local but that is the default).

Also in the output of the error message:
Omit --global to set the identity only in this repository.

As for using the environment variables vs calling git config itself, i have no preference

Copy link
Contributor

Choose a reason for hiding this comment

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

If those git config commands fail, they'd be ignored (because we are running them through call_quietly), and we'd still run into the original issue?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@azharudd The commands will raise an exception

def call_quietly(*args, **kwargs):
    kwargs['stderr'] = subprocess.STDOUT
    try:
        subprocess.check_output(*args, **kwargs)
    except subprocess.CalledProcessError as e:
        raise CallQuietlyException(command=e.cmd, returncode=e.returncode,
                                   output=e.stdout) from e

call_quietly is intended to suppress stdout from what I'm gathering, not suppress exceptions (a bit confusing)

@azharudd
Copy link
Contributor

Instead of executing those git commands, an alternative would be to set the corresponding environment variables.

os.environ['GIT_AUTHOR_NAME'] = 'swift_test'
os.environ['GIT_COMMITTER_NAME'] = 'swift_test'
os.environ['GIT_AUTHOR_EMAIL'] = '<[email protected]>'
os.environ['GIT_COMMITTER_EMAIL'] = '<[email protected]>'

This could be done within that function, and it also doesn't affect the git config.

@justice-adams-apple
Copy link
Contributor Author

@swift-ci test

@justice-adams-apple
Copy link
Contributor Author

@swift-ci test

@justice-adams-apple justice-adams-apple merged commit 1e1512a into main May 1, 2023
@justice-adams-apple justice-adams-apple deleted the PR/add-git-config-to-update-checkout-scheme branch May 1, 2023 18:50
justice-adams-apple added a commit that referenced this pull request May 1, 2023
* add username/email to bare git config in repo

* update mock username/email

* remove extra whitespace, fix linter
justice-adams-apple added a commit that referenced this pull request May 5, 2023
* add username/email to bare git config in repo

* update mock username/email

* remove extra whitespace, fix linter
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants