Skip to content

Conversation

venlinz
Copy link

@venlinz venlinz commented May 1, 2022

Fixes issue: #3751

This will add support for git_commit__create_internal() for getting AUTHOR and COMMITTER information from the ENVIRONMENT.
variables considered as follows,
GIT_AUTHOR_NAME
GIT_AUTHOR_EMAIL // for AUTHOR information
and
GIT_COMMITTER_NAME
GIT_COMMITTER_EMAIL // for information

if one of the env variable in a set(AUTHOR env pair)
and other is not set or set to empty string(eg.: GIT_AUTHOR_NAME is set and GIT_AUTHOR_EMAIL is set to empty string or not setted at all) this patch will
defaults to global values for the empty string value or unsetted ENV variable and takes the properly set ENV variable with non-empty string and stores as a git_signature structure in git_commit__create_internal, but in git CLI the commit will fail instead of defaulting to
global defaults for empty string value for a ENV variable such as GIT_AUTHOR_EMAIL.

on the other hand if one of a variable in pair is not set(eg. GIT_AUTHOR_NAME is set and GIT_AUTHOR_EMAIL is not set) and other one is set to valid value ENV git CLI sets global defaults values for unsetted ENV variable.
I'm using git version 2.36.0.

This will add support for git_commit__create_internal() for
getting AUTHOR and COMMITTER information from the ENVIRONMENT
variables that are set as follows,
           GIT_AUTHOR_NAME
           GIT_AUTHOR_EMAIL // for AUTHOR information
and
           GIT_COMMITTER_NAME
           GIT_COMMITTER_EMAIL // for  information

if one of the env variable in a set(AUTHOR env pair)
and other is not set(ie.: GIT_AUTHOR_NAME is set and
GIT_AUTHOR_EMAIL is set to empty string) this patch will
defaults to global values for the empty string value and
takes the properly ENV variable with non-empty string,
but in git CLI the commit will fail instead of defaulting to
global defaults for empty string value for a ENV variable
such as GIT_AUTHOR_EMAIL.

if a ENV variable is not set git CLI defaults to global
defaults.
@venlinz
Copy link
Author

venlinz commented May 1, 2022

I am working on adding tests to check the functionality of this patch , if you think the patch does the correct job please let me know, if it's not solves the please let me know where I went wrong. I eagerly looking forward for reply thank you.

u-quark added a commit to u-quark/libgit2 that referenced this pull request Dec 21, 2023
When creating an action signature (e.g. for a commit author and
committer) read the following environment variables that can override
the configuration options:

 * `GIT_AUTHOR_NAME` is the human-readable name in the "author" field.
 * `GIT_AUTHOR_EMAIL` is the email for the "author" field.
 * `GIT_AUTHOR_DATE` is the timestamp used for the "author" field.
 * `GIT_COMMITTER_NAME` sets the human name for the "committer" field.
 * `GIT_COMMITTER_EMAIL` is the email address for the "committer" field.
 * `GIT_COMMITTER_DATE` is used for the timestamp in the "committer"
   field.
 * `EMAIL` is the fallback email address in case the user.email
   configuration value isn't set. If this isn't set, Git falls back to
   the system user and host names.

This is taken from the git documentation chapter "10.8 Environment
Variables":

https://git-scm.com/book/en/v2/Git-Internals-Environment-Variables

This PR adds support for reading these environment variables by adding
two new functions `git_signature_default_author` and
`git_signature_default_committer` and deprecates the
`git_signature_default` function.

Fixes: libgit2#3751

Prior work:
 * libgit2#4409
 * libgit2#5479
 * libgit2#6290
u-quark added a commit to u-quark/libgit2 that referenced this pull request Jan 14, 2024
When creating an action signature (e.g. for a commit author and
committer) read the following environment variables that can override
the configuration options:

 * `GIT_AUTHOR_NAME` is the human-readable name in the "author" field.
 * `GIT_AUTHOR_EMAIL` is the email for the "author" field.
 * `GIT_AUTHOR_DATE` is the timestamp used for the "author" field.
 * `GIT_COMMITTER_NAME` sets the human name for the "committer" field.
 * `GIT_COMMITTER_EMAIL` is the email address for the "committer" field.
 * `GIT_COMMITTER_DATE` is used for the timestamp in the "committer"
   field.
 * `EMAIL` is the fallback email address in case the user.email
   configuration value isn't set. If this isn't set, Git falls back to
   the system user and host names.

This is taken from the git documentation chapter "10.8 Environment
Variables":

https://git-scm.com/book/en/v2/Git-Internals-Environment-Variables

This PR adds support for reading these environment variables by adding
two new functions `git_signature_default_author` and
`git_signature_default_committer` and deprecates the
`git_signature_default` function.

Fixes: libgit2#3751

Prior work:
 * libgit2#4409
 * libgit2#5479
 * libgit2#6290
@ethomson
Copy link
Member

Fixed via #6706 ; thanks for the patch, sorry that this went a while without a review and that caused a duplicated effort. 🙏

@ethomson ethomson closed this Aug 27, 2024
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.

2 participants