Skip to content
  • Paul Tan's avatar
    git-credential-store: support multiple credential files · cb2c2796
    Paul Tan authored and Junio C Hamano's avatar Junio C Hamano committed
    Previously, git-credential-store only supported storing credentials in a
    single file: ~/.git-credentials. In order to support the XDG base
    directory specification[1], git-credential-store needs to be able to
    lookup and erase credentials from multiple files, as well as to pick the
    appropriate file to write to so that the credentials can be found on
    subsequent lookups.
    
    [1] http://standards.freedesktop.org/basedir-spec/basedir-spec-0.7.html
    
    
    
    Note that some credential storage files may not be owned, readable or
    writable by the user, as they may be system-wide files that are meant to
    apply to every user.
    
    Instead of a single file path, lookup_credential(), remove_credential()
    and store_credential() now take a precedence-ordered string_list of
    file paths. lookup_credential() expects both user-specific and
    system-wide credential files to be provided to support the use case of
    system administrators setting default credentials for users.
    remove_credential() and store_credential() expect only the user-specific
    credential files to be provided as usually the only config files that
    users are allowed to edit are their own user-specific ones.
    
    lookup_credential() will read these (user-specific and system-wide) file
    paths in order until it finds the 1st matching credential and print it.
    As some files may be private and thus unreadable, any file which cannot
    be read will be ignored silently.
    
    remove_credential() will erase credentials from all (user-specific)
    files in the list.  This is because if credentials are only erased from
    the file with the highest precedence, a matching credential may still be
    found in a file further down the list. (Note that due to the lockfile
    code, this requires the directory to be writable, which should be so for
    user-specific config files)
    
    store_credential() will write the credentials to the first existing
    (user-specific) file in the list. If none of the files in the list
    exist, store_credential() will write to the filename specified by the
    first item of the filename list. For backwards compatibility, this
    filename should be "~/.git-credentials".
    
    Helped-by: default avatarMatthieu Moy <Matthieu.Moy@grenoble-inp.fr>
    Helped-by: default avatarJunio C Hamano <gitster@pobox.com>
    Helped-by: default avatarJeff King <peff@peff.net>
    Signed-off-by: default avatarPaul Tan <pyokagan@gmail.com>
    Reviewed-by: default avatarMatthieu Moy <Matthieu.Moy@imag.fr>
    Signed-off-by: default avatarJunio C Hamano <gitster@pobox.com>
    cb2c2796