From: Stefan Beller Date: Tue, 26 Jul 2016 00:59:03 GMT Subject: Re: [PATCH v4 1/4] worktree: add per-worktree config files Message-ID: In-Reply-To: <20160720172419.25473-2-pclouds@gmail.com> On Wed, Jul 20, 2016 at 10:24 AM, Nguyễn Thái Ngọc Duy wrote: > A new repo extension is added, worktreeConfig. When it is present: > > - Repository config reading by default includes $GIT_DIR/config _and_ > $GIT_DIR/config.worktree. "config" file remains shared in multiple > worktree setup. > > - The special treatment for core.bare and core.worktree, to stay > effective only in main worktree, is gone. These config files are > supposed to be in config.worktree. > > This extension is most useful in multiple worktree setup because you > now have an option to store per-worktree config (which is either > .git/config.worktree for main worktree, or > .git/worktrees/xx/config.worktree for linked ones). > > This extension can be used in single worktree mode, even though it's > pretty much useless (but this can happen after you remove all linked > worktrees and move back to single worktree). > > "git config" reads from both "config" and "config.worktree" by default > (i.e. without either --user, --file...) when this extension is > present. Default writes still go to "config", not "config.worktree". A > new option --worktree is added for that (*). > > Since a new repo extension is introduced, existing git binaries should > refuse to access to the repo (both from main and linked worktrees). So > they will not misread the config file (i.e. skip the config.worktree > part). They may still accidentally write to the config file anyway if > they use with "git config --file ". > > This design places a bet on the assumption that the majority of config > variables are shared so it is the default mode. A safer move would be > default writes go to per-worktree file, so that accidental changes are > isolated. > > (*) "git config --worktree" points back to "config" file when this > extension is not present so that it works in any setup. > > Signed-off-by: Nguyễn Thái Ngọc Duy I like the user facing design, but how am I supposed to use it internally? Say I want to read a value preferably from the worktree I'd do a /* * maybe I don't even have to set it to 1 as * the user is supposed to do that? */ repository_format_worktree_config = 1; git_config_get_{string,bool,int} (... as usual ...) and if I want to read the value globally I would set the variable to 0 and read? (I would need to restore it, so I'll have a temporary variable to keep the original value of repository_format_worktree_config) Thanks, Stefan > --- > Documentation/config.txt | 11 ++++- > Documentation/git-config.txt | 26 ++++++++---- > Documentation/git-worktree.txt | 31 ++++++++++++++ > Documentation/gitrepository-layout.txt | 8 ++++ > builtin/config.c | 18 +++++++- > cache.h | 2 + > config.c | 7 ++++ > environment.c | 1 + > setup.c | 5 ++- > t/t2028-worktree-config.sh (new +x) | 77 ++++++++++++++++++++++++++++++++++ > 10 files changed, 175 insertions(+), 11 deletions(-) > create mode 100755 t/t2028-worktree-config.sh > > diff --git a/Documentation/config.txt b/Documentation/config.txt > index 16dc22d..7d64da0 100644 > --- a/Documentation/config.txt > +++ b/Documentation/config.txt > @@ -2,8 +2,9 @@ CONFIGURATION FILE > ------------------ > > The Git configuration file contains a number of variables that affect > -the Git commands' behavior. The `.git/config` file in each repository > -is used to store the configuration for that repository, and > +the Git commands' behavior. The files `.git/config` and optionally > +`config.worktree` (see `extensions.worktreeConfig` below) are each > +repository is used to store the configuration for that repository, and > `$HOME/.gitconfig` is used to store a per-user configuration as > fallback values for the `.git/config` file. The file `/etc/gitconfig` > can be used to store a system-wide default configuration. > @@ -264,6 +265,12 @@ advice.*:: > show directions on how to proceed from the current state. > -- > > +extensions.worktreeConfig:: > + If set, by default "git config" reads from both "config" and > + "config.worktree" file in that order. In multiple working > + directory mode, "config" file is shared while > + "config.worktree" is per-working directory. > + > core.fileMode:: > Tells Git if the executable bit of files in the working tree > is to be honored. > diff --git a/Documentation/git-config.txt b/Documentation/git-config.txt > index f163113..9dfdb6a 100644 > --- a/Documentation/git-config.txt > +++ b/Documentation/git-config.txt > @@ -47,13 +47,15 @@ checks or transformations are performed on the value. > > When reading, the values are read from the system, global and > repository local configuration files by default, and options > -`--system`, `--global`, `--local` and `--file ` can be > -used to tell the command to read from only that location (see <>). > +`--system`, `--global`, `--local`, `--worktree` and > +`--file ` can be used to tell the command to read from only > +that location (see <>). > > When writing, the new value is written to the repository local > configuration file by default, and options `--system`, `--global`, > -`--file ` can be used to tell the command to write to > -that location (you can say `--local` but that is the default). > +`--worktree`, `--file ` can be used to tell the command to > +write to that location (you can say `--local` but that is the > +default). > > This command will fail with non-zero status upon error. Some exit > codes are: > @@ -133,6 +135,11 @@ from all available files. > + > See also <>. > > +--worktree:: > + Similar to `--local` except that `.git/config.worktree` is > + read from or written to if `extensions.worktreeConfig` is > + present. If not it's the same as `--local`. > + > -f config-file:: > --file config-file:: > Use the given config file instead of the one specified by GIT_CONFIG. > @@ -253,6 +260,10 @@ $XDG_CONFIG_HOME/git/config:: > $GIT_DIR/config:: > Repository specific configuration file. > > +$GIT_DIR/config.worktree:: > + This is optional and is only searched when > + `extensions.worktreeConfig` is present in $GIT_DIR/config. > + > If no further options are given, all reading options will read all of these > files that are available. If the global or the system-wide configuration > file are not available they will be ignored. If the repository configuration > @@ -268,9 +279,10 @@ configuration file. Note that this also affects options like `--replace-all` > and `--unset`. *'git config' will only ever change one file at a time*. > > You can override these rules either by command-line options or by environment > -variables. The `--global` and the `--system` options will limit the file used > -to the global or system-wide file respectively. The `GIT_CONFIG` environment > -variable has a similar effect, but you can specify any filename you want. > +variables. The `--global`, `--system` and `--worktree` options will limit > +the file used to the global, system-wide or per-worktree file respectively. > +The `GIT_CONFIG` environment variable has a similar effect, but you > +can specify any filename you want. > > > ENVIRONMENT > diff --git a/Documentation/git-worktree.txt b/Documentation/git-worktree.txt > index 7c4cfb0..41350db 100644 > --- a/Documentation/git-worktree.txt > +++ b/Documentation/git-worktree.txt > @@ -111,6 +111,37 @@ OPTIONS > --expire