Skip to content

use .lfsconfig (with fallback to .gitconfig) - #837

Merged
technoweenie merged 7 commits into
masterfrom
use-lfsconfig
Nov 18, 2015
Merged

technoweenie merged 7 commits into
masterfrom
use-lfsconfig

Conversation

@technoweenie

Copy link
Copy Markdown
Contributor

This changes Git LFS to read committed lfs config settings from .lfsconfig instead of .gitconfig. This makes it more clear what settings should go in that file. It does continue to check for .gitconfig but only IF .lfsconfig does not exist. This is meant as a way for projects to gradually rename this file on their own. By Git LFS v2.0, we'll remove support completely.

This also makes a few other changes:

  • ListFromFile() doesn't run os.Stat anymore. The new readGitConfigFromFiles() function minimizes os.Stat calls.
  • The config order was tweaked slightly, reducing the number of git config calls. No need to call git config --list AND git config --file .git/config --list. Now it only calls git config --file .lfsconfig --list and git config --list.

Fixes #780

@technoweenie technoweenie mentioned this pull request Nov 16, 2015
7 of 13 tasks
@technoweenie technoweenie mentioned this pull request Nov 16, 2015
Comment thread lfs/config.go Outdated

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Add the issue # tracking this work so that when we complete the work we know to remove the TODO.

@technoweenie technoweenie mentioned this pull request Nov 16, 2015
2 tasks done
technoweenie added a commit that referenced this pull request Nov 18, 2015
use .lfsconfig (with fallback to .gitconfig)
@technoweenie
technoweenie merged commit 14aeecc into master Nov 18, 2015
@technoweenie
technoweenie deleted the use-lfsconfig branch November 18, 2015 00:24
Comment thread git/git.go

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

837

chrisd8088 added a commit that referenced this pull request Oct 22, 2026
In commits dcb2d4e and
265feee of PR #837 we
updated the "git lfs env" command to output a warning when
a Git configuration option was defined more than once.  Later,
in commit dcae83d of PR #861,
we limited these warnings so they are only reported for options
in the "lfs" configuration section.

At present, the readGitConfig() function in our "config" package
tracks which configuration options it has parsed so far using an
internal map named "uniqKeys".  During a "git lfs env" command,
the function refers to the map to check if an option in the "lfs"
configuration section has been encountered previously.  If so,
and if the value of the current option differs from the value
set previously for the option, then the function outputs a warning
message.

In a subsequent commit, we expect to revise the readGitConfig()
function and simplify the variables it uses to populate the
"uniqKeys" map.

Before we do so, though, we first add a shell integration test
which verifies that the "git lfs env" command reports the expected
warnings when an option in the "lfs" section has multiple different
values.  The test also checks that the "git lfs env" command does
not report duplicate values of configuration options that are not
in the "lfs" section.

Our new test will then serve to guarantee that when we update
the readGitConfig() function in subsequent commits, we do not
inadvertently alter its handling of duplicate option values.

Co-authored-by: Chris Darroch <[email protected]>
chrisd8088 added a commit that referenced this pull request Oct 22, 2026
In commits dcb2d4e and
265feee of PR #837 we
updated the "git lfs env" command to output a warning when
a Git configuration option was defined more than once.  Later,
in commit dcae83d of PR #861,
we limited these warnings so they are only reported for options
in the "lfs" configuration section.

At present, the readGitConfig() function in our "config" package
tracks which configuration options it has parsed so far using an
internal map named "uniqKeys".  During a "git lfs env" command,
the function refers to the map to check if an option in the "lfs"
configuration section has been encountered previously.  If so,
and if the value of the current option differs from the value
set previously for the option, then the function outputs a warning
message.

The readGitConfig() function accepts Git configuration data in
the form generated by the ParseConfigLines() function of our
"git" package.  Currently, this function splits the output of
"git config -l" commands on each line feed (LF) character, so
the readGitConfig() function then iterates over those lines and
splits each one on the first equals sign ("=") character to
determine the name and value of a configuration option.

As each option is processed, its name and value are stored in a
slice variable named "pieces", whose two elements are then
assigned to variables named "key" and "val", respectively.
For the most part, the remainder of the per-option loop refers
to the current option's name and value via the "key" and "val"
variables.

However, when populating the "uniqKeys" map and when generating
warning messages about multiple values for a single option, we
refer directly to the first element of the "pieces" slice even
though this element's value will always be identical to that
of the "key" variable.

In a subsequent commit, we expect to revise our parsing of Git
configuration sources to support values which contain line feed
(LF) characters.  The readGitConfig() function will therefore iterate
over a slice of configuration entry structures rather than parse
individual lines, and so will no longer require a "pieces" slice.

Before we make these changes, we first update the two instances
where we refer to the first element of the "pieces" slice so they
instead refer to the "key" variable.  This will permit us to more
easily remove the "pieces" slice entirely in a subsequent commit.
Since the "key" variable and the first element of the "pieces"
slice are always identical, this change will not alter either the
option names stored in the "uniqKeys" map or those reported in
warnings by the "git lfs env" command.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants