introduce GIT_WORK_DIR environment variable
RFC 1/1 introduce GIT_WORK_DIR environment variable
This environment variable can be used with GIT_DIR to specify the toplevel working directory. When GIT_DIR is not set this variable is ignored. As for GIT_DIR there is also the option git --work-dir which overrides the environment variable.
---
Missing:
Documentation update but if this feature should not get accepted.. therefore I'll wait for feedback first.
Idea:
Add some way to configure tho working directory for one repository and set GIT_WORK_DIR automatically when GIT_DIR is used. I think of:
* a subdirectory in the repository directory
e.g. .git/work_dir which is supposed to be a symlink (or a textfile containing the path for windows compatibility?)
or
* a configuration variable
Considerations:
Without running setup_git_directory_gently is_bare_repository and is_inside_git_dir may return wrong values. Except for cmd_init_db I found no place calling on of the functions without calling setup_git_directory_gently before.
To do:
git init should probably set bare = false when GIT_WORK_DIR is exported. And if the idea about configurable working directories gets implemented it could also set this option accordingly.
--- cache.h | 2 + environment.c | 2 + git.c | 12 +++++++++- setup.c | 70 ++++++++++++++++++++++++++++++++++++++++++++++++++++---- 4 files changed, 80 insertions(+), 6 deletions(-)
cache.h +2 -0
@@ -144,6 +144,7 @@ enum object_type { };#define GIT_DIR_ENVIRONMENT "GIT_DIR" +#define GIT_WORKING_DIR_ENVIRONMENT "GIT_WORK_DIR"#define DEFAULT_GIT_DIR_ENVIRONMENT ".git"#define DB_ENVIRONMENT "GIT_OBJECT_DIRECTORY"#define INDEX_ENVIRONMENT "GIT_INDEX_FILE"
@@ -164,6 +165,7 @@ extern char *get_graft_file(void);#define ALTERNATE_DB_ENVIRONMENT "GIT_ALTERNATE_OBJECT_DIRECTORIES" +extern int has_working_directory;extern const char **get_pathspec (const char *prefix,const char **pathspec);extern const char *setup_git_directory_gently (int *);extern const char *setup_git_directory (void );
environment.c +2 -0
@@ -61,6 +61,8 @@ int is_bare_repository(void)const char *dir, *s;if (0 <= is_bare_repository_cfg)return is_bare_repository_cfg; +if (0 <= has_working_directory) +return !has_working_directory; dir =get_git_dir ();if (!strcmp (dir,DEFAULT_GIT_DIR_ENVIRONMENT ))
git.c +11 -1
@@ -4,7 +4,7 @@#include "quote.h" const char git_usage_string[] = -"git [--version] [--exec-path[=GIT_EXEC_PATH]] [-p|--paginate] [--bare] [--git-dir=GIT_DIR] [--help] COMMAND [ARGS]" ; +"git [--version] [--exec-path[=GIT_EXEC_PATH]] [-p|--paginate] [--bare] [--git-dir=GIT_DIR] [--work-dir=GIT_WORK_DIR] [--help] COMMAND [ARGS]" ;static void prepend_to_path (const char *dir,int len) {
@@ -68,6 +68,16 @@ static int handle_options(const char*** argv, int* argc) (*argc)--; }else if (!prefixcmp (cmd,"--git-dir=" )) {setenv (GIT_DIR_ENVIRONMENT , cmd +10 ,1 ); + }else if (!strcmp (cmd,"--work-dir" )) { +if (*argc <2 ) { +fprintf (stderr,"No directory given for --work-dir.\n" ); +usage (git_usage_string); + } +setenv (GIT_WORKING_DIR_ENVIRONMENT , (*argv)[1 ],1 ); + (*argv)++; + (*argc)--; + }else if (!prefixcmp (cmd,"--work-dir=" )) { +setenv (GIT_WORKING_DIR_ENVIRONMENT , cmd +11 ,1 ); }else if (!strcmp (cmd,"--bare" )) {static char git_dir[PATH_MAX +1 ];setenv (GIT_DIR_ENVIRONMENT ,getcwd (git_dir,sizeof (git_dir)),1 );
setup.c +65 -5
86 lines not on this page · raw message
Signature · 1 line
1.5.0.3
PATCH 1/1 git-init: set up GIT_DIR/workdir if GIT_WORK_DIR is set
git-init will always put an absolute path in GIT_DIR/workdir, relative paths are resolved from the directory git-init was called from.
---
I found this static char path[PATH_MAX] even though path is neither reused nor returned. If there is any reason to have this as a static buffer please change this back to 'static char'
--- builtin-init-db.c | 40 ++++++++++++++++++++++++++++++++++++++-- 1 files changed, 38 insertions(+), 2 deletions(-)
builtin-init-db.c +38 -2
@@ -176,12 +176,13 @@ static void copy_templates(const char *git_dir, int len, const char *template_distatic int create_default_files (const char *git_dir,const char *template_path) {unsigned len =strlen (git_dir); -static char path[PATH_MAX ]; +char path[PATH_MAX ], workdir[PATH_MAX ];unsigned char sha1[20 ];struct stat st1;char repo_version_string[10 ];int reinit;int filemode; +const char *gitwd =getenv (GIT_WORKING_DIR_ENVIRONMENT );if (len >sizeof (path)-50 )die ("insane git directory %s" , git_dir);
@@ -252,7 +253,42 @@ static int create_default_files(const char *git_dir, const char *template_path) }git_config_set ("core.filemode" , filemode ?"true" :"false" ); -if (is_bare_repository ()) { +/* make gitwd an absolute path */ +if (gitwd && gitwd[0 ] !='/' ) { +char cwd[PATH_MAX ]; + +if (!getcwd (cwd,sizeof (cwd)) || cwd[0 ] !='/' ) +die ("Unable to read current working directory" ); +if (chdir (gitwd)) { +fprintf (stderr,"warning: chdir to specified relative " +"working directory failed, ignoring\n" ); + gitwd =NULL ; + } +else if (!getcwd (workdir,sizeof (workdir)) || workdir[0 ] !='/' ) +die ("Unable to read current working directory" ); +else { + gitwd = workdir; +if (chdir (cwd)) +die ("Cannot come back to cwd" ); + } + } + +if (gitwd) { +FILE *fp =NULL ; + + path[len] =0 ; +strcpy (path + len,"workdir" ); +if (!(fp =fopen (path,"w" ))) +die ("Cannot open GIT_DIR/workdir" ); +fprintf (fp,"%s\n" , gitwd); +fclose (fp); + +git_config_set ("core.bare" ,"false" ); +/* allow template config file to override the default */ +if (log_all_ref_updates ==-1 ) +git_config_set ("core.logallrefupdates" ,"true" ); + } +else if (is_bare_repository ()) {git_config_set ("core.bare" ,"true" ); }else {
Signature · 1 line
1.5.0.3.1006.gd633
Re: [PATCH] git-init: set up GIT_DIR/workdir if GIT_WORK_DIR is set
Quoted 3 lines · Matthias Lederhofer
git-init will always put an absolute path in GIT_DIR/workdir, relative paths are resolved from the directory git-init was called from.
Does that mean I can't move my GIT trees around without changing a config entry? What is that an improvement?
Re: [PATCH] git-init: set up GIT_DIR/workdir if GIT_WORK_DIR is set
Quoted 7 lines · Joshua N Pritikin
Quoted 3 lines · Matthias Lederhofer
git-init will always put an absolute path in GIT_DIR/workdir, relative paths are resolved from the directory git-init was called from.
Does that mean I can't move my GIT trees around without changing a config entry? What is that an improvement?
Only when using $GIT_DIR. $GIT_DIR/workdir is only the default value for $GIT_WORK_DIR.
Re: [PATCH] git-init: set up GIT_DIR/workdir if GIT_WORK_DIR is set
In reply to Joshua N PritikinQuoted 7 lines · Joshua N Pritikin
Quoted 3 lines · Matthias Lederhofer
git-init will always put an absolute path in GIT_DIR/workdir, relative paths are resolved from the directory git-init was called from.
Does that mean I can't move my GIT trees around without changing a config entry? What is that an improvement?
And for the decision to put an absolute path there by default:
Putting $GIT_WORK_DIR as is into $GIT_DIR/workdir is probably not what the user expects because the content of $GIT_DIR/workdir is interpreted relative to $GIT_DIR, not the current working directory. Example:
/tmp$ mkdir repository working_directory
/tmp$ git --git-dir=repository --work-dir=working_directory init
If git init puts 'working_directory' into $GIT_DIR/workdir it would make the associated working directory $GIT_DIR/working_directory = /tmp/repository/working_directory and not /tmp/working_directory.
The alternative to use
/tmp$ git --git-dir=repository --work-dir=../working_directory init
seems quite confusing to me.
If you've any other idea to solve this please tell me.
Re: [PATCH] git-init: set up GIT_DIR/workdir if GIT_WORK_DIR is set
Quoted 12 lines · Matthias Lederhofer
Putting $GIT_WORK_DIR as is into $GIT_DIR/workdir is probably not what the user expects because the content of $GIT_DIR/workdir is interpreted relative to $GIT_DIR, not the current working directory. Example:
/tmp$ mkdir repository
working_directory
/tmp$ git --git-dir=repository --work-dir=working_directory initIf git init puts '
working_directory' into $GIT_DIR/workdir it would make the associated working directory $GIT_DIR/working_directory =/tmp/repository/working_directoryand not/tmp/working_directory.
Quoted 7 lines
The alternative to use
/tmp$ git --git-dir=repository --work-dir=../working_directory initseems quite confusing to me.
If you've any other idea to solve this please tell me.
Let users create $GIT_DIR/workdir themselves. Your way may be less confusing to you but might be more confusing to me because I _might_ expect a relative workdir setting (for example I move the repository and the working directory together to another place).
Signature · 1 line
Duy
Re: [PATCH] git-init: set up GIT_DIR/workdir if GIT_WORK_DIR is set
Quoted 4 lines · Nguyen Thai Ngoc Duy
Let users create $GIT_DIR/workdir themselves. Your way may be less confusing to you but might be more confusing to me because I _might_ expect a relative workdir setting (for example I move the repository and the working directory together to another place).
Well, without this patch you havo to do one of these:
/tmp$ mkdir repository working_directory /tmp$ git --git-dir=repository init
/tmp$ git --git-dir=repository config core.bare false /tmp$ echo ../working_directory > repository/workdir
or
/tmp$ mkdir repository working_directory /tmp/repository$ cd repository
/tmp$ git init
/tmp/repository$ mv .git/* . /tmp/repository$ rmdir .git
/tmp$ echo ../working_directory > repository/workdir
Where the second example is probably better because git init creates a bare repository in the first case which might have more settings different from a 'normal' repository (it actually sets also core.logallrefupdates = true which probably should be added to the first example).
With this patch you'd have to do
/tmp$ mkdir repository working_directory
/tmp$ git --git-dir=repository --work-dir=working_directory init /tmp$ echo ../working_directory > repository/workdir
in case you really want a relative path.
Because the first two ways are so long I think git init should have some way to handle this case.
I don't want to put $GIT_WORK_DIR 'as is' to $GIT_DIR/workdir because $GIT_WORK_DIR is normally interpreted as relative path to the current working directory and not relative to $GIT_DIR.
Perhaps we could add another flag to git init which will be used 'as is' for $GIT_DIR/workdir:
git --git-dir=repository init --work-dir=../working_directory
Other things I can think of:
Add a --not-bare flag to git init:
$ git --git-dir=repository init --not-bare $ echo ../working_directory > repository/workdir
Tell the user what to do in case the path should be relative:
$ git --git-dir=repository --work-dir=working_directory init You specified a relative working directory and git has automatically expanded this to /tmp/working_directory. If you prefer a relative path you can do:
echo relative_path > repository/workdir
Re: [PATCH] git-init: set up GIT_DIR/workdir if GIT_WORK_DIR is set
Quoted 3 lines · Matthias Lederhofer
... because
$GIT_WORK_DIR is normally interpreted as relative path to the current working directory and not relative to $GIT_DIR.
Well, it could be that _that_ handling of the environment variable is what needs to be fixed.
If you are using $GIT_DIR, you are working in a subdirectory, say, Documentation/, and you are using a relative path to specify GIT_WORK_DIR, then you would need to do this, right?
$ GIT_DIR=/src/git/git.git ;# top of repository
$ export GIT_DIR
$ cd /work/git/git.git ;# go to top of working tree
$ cd Documentation ;# I want to work in here... $ GIT_WORK_DIR=.. ;# toplevel is .. relative to here
$ export GIT_WORK_DIR
$ hack hack ; git commit $ cd .. ;# Now I want to update the toplevel
$ GIT_WORK_DIR=. ;# oops I need to update this env
$ hack hack ; git commit $ cd t ;# Now to testcase
$ GIT_WORK_DIR=.. ;# oops againIf $GIT_WORK_DIR is given absolute you do not have to worry about this problem, but if you allow giving relative path, it seems to me that it would be more useful to make it relative to GIT_DIR. Then you would need to set it just once, at the same time when you set and export GIT_DIR, and keep working in that working tree.
The same goes for $GIT_DIR/workdir.
Re: [PATCH] git-init: set up GIT_DIR/workdir if GIT_WORK_DIR is set
Quoted 8 lines · Junio C Hamano
Quoted 3 lines · Matthias Lederhofer
... because
$GIT_WORK_DIR is normally interpreted as relative path to the current working directory and not relative to $GIT_DIR.Well, it could be that _that_ handling of the environment variable is what needs to be fixed.
You're right, this seems to be much better.
I just thought that GIT_WORK_DIR should be relative to the current working directory because it's more intuitive, e.g.
$ git --git-dir=/path/to/repo.git --work-dir=../.. add a
where ../.. matches the path to the toplevel working directory from cwd. But this definitely is annoying when changing directories.
I'll go and fix this. Do you prefer an amended patch or just a patch on top?
PATCH 1/1 always interpret GIT_WORK_DIR relative to $GIT_DIR
--- setup.c | 39 +++++++++++++++++++++++---------------- 1 files changed, 23 insertions(+), 16 deletions(-)
setup.c +23 -16
@@ -192,16 +192,36 @@ int is_inside_git_dir(void)return inside_git_dir; } +static int stat_relative (const char *base,const char *path,struct stat *st) +{ +char cwd[PATH_MAX ]; +int ret; + +if (path[0 ] !='/' ) { +if (!getcwd (cwd,sizeof (cwd)) || cwd[0 ] !='/' ) +die ("Unable to read current working directory" ); +if (chdir (base)) +die ("Cannot change directory to '%s'" , base); + } + + ret =stat (path, st); + +if (path[0 ] !='/' &&chdir (cwd)) +die ("Cannot come back to cwd" ); + +return ret; +} +static int stat_git_work_dir (struct stat *st) { -char workdir[PATH_MAX ], cwd[PATH_MAX ]; +char workdir[PATH_MAX ];const char *gitdir =getenv (GIT_DIR_ENVIRONMENT );const char *gitwd =getenv (GIT_WORKING_DIR_ENVIRONMENT );int offset;FILE *fp;if (gitwd) { -if (!stat (gitwd, st)) +if (!stat_relative (gitdir, gitwd, st))return 1 ;die ("Unable to stat git working directory '%s'" , gitwd); }
@@ -231,21 +251,8 @@ static int stat_git_work_dir(struct stat *st) --offset; workdir[offset+1 ] ='\0' ; -/* relative path: change to gitdir for stat */ -if (workdir[0 ] !='/' ) { -if (!getcwd (cwd,sizeof (cwd)) || cwd[0 ] !='/' ) -die ("Unable to read current working directory" ); -if (chdir (gitdir)) -die ("Cannot change directory to '%s'" , gitdir); - } - -if (stat (workdir, st)) +if (stat_relative (gitdir, workdir, st))die ("Unable to stat directory from GIT_DIR/workdir" ); -if (!(st->st_mode &S_IFDIR )) -die ("GIT_DIR/workdir does not point to a directory" ); - -if (workdir[0 ] !='/' &&chdir (cwd)) -die ("Cannot come back to cwd" );return 1 ; }
Signature · 1 line
1.5.0.3.1007.g7ff7
PATCH 1/1 GIT_WORK_DIR: documentation for relative path
--- Documentation/git.txt | 22 +++++++++++++--------- 1 files changed, 13 insertions(+), 9 deletions(-)
Documentation/git.txt +13 -9
@@ -83,11 +83,13 @@ OPTIONS setting the GIT_DIR environment variable. --work-dir=<path>:: - Set the path to the toplevel working directory. The value will - be used only in combination with $GIT_DIR or '--git-dir'. - Without this option git will assume that the current directory - is also the toplevel directory. This can also be controlled by - setting the GIT_WORK_DIR environment variable. + Set the path to the toplevel working directory. If the path is + relative it is interpreted from $GIT_DIR, not the current + working directory. The value will be used only in combination + with $GIT_DIR or '--git-dir'. Without this option git will + assume that the current working directory is also the toplevel + directory. This can also be controlled by setting the + GIT_WORK_DIR environment variable. --bare:: Same as --git-dir=`pwd`.
@@ -334,10 +336,12 @@ git so take care if using Cogito etc. for the base of the repository. 'GIT_WORK_DIR':: - Set the path to the toplevel working directory. The value will - be used only in combination with $GIT_DIR or '--git-dir'. - Without this environment variable git will assume that the - current directory is also the toplevel directory. + Set the path to the toplevel working directory. If the path is + relative it is interpreted from $GIT_DIR, not the current + working directory. The value will be used only in combination + with $GIT_DIR or '--git-dir'. Without this environment variable + git will assume that the current working directory is also the + toplevel directory. git Commits ~~~~~~~~~~~
Signature · 1 line
1.5.0.3.1007.g7ff7
Re: [PATCH] git-init: set up GIT_DIR/workdir if GIT_WORK_DIR is set
In reply to Matthias LederhoferQuoted 7 lines · Matthias Lederhofer
I just thought that
GIT_WORK_DIRshould be relative to the current working directory because it's more intuitive, e.g.$ git --git-dir=/path/to/repo.git --work-dir=../.. add awhere ../.. matches the path to the toplevel working directory from cwd. But this definitely is annoying when changing directories.
Not so fast. That was a trick suggestion, only meant to see if you have thought through the issues, and you did not have to agree with me so quickly ;-). What I was pointing out was merely that specifying the top as a path relative to the cwd in permanent basis was not useful if you are going to cd around, which is a tautology.
For a one-shot thing, I would agree that being able to say "I am in Documentation/howto directory of the whole thing, so I can name the top of my working tree as ../.." is far more useful and natural than having to say "ehhhh, what is the top of the working tree relative to my repository???". If it is not a one-shot thing and the user expects to cd around, then:
$ GIT_WORK_DIR=$(pwd)/../..; export GIT_WORK_DIR $ git foo ...; git bar ...;
would be more natural, so I do not expect the semantics of relative path would be a big issue in reality, as long as we make it clear that it is relative to cwd.
By the way, I do not find your command line example intuitive at all, whether the --work-dir= parameter is relative or absolute. Do you honestry expect that loooong command line is something people would use in real life?
With $GIT_DIR/workdir support, I would expect that people would do (if what is done is only to add one file and nothing else):
$ GIT_DIR=/path/to/repo.git git add a
And without $GIT_DIR/workdir support:
$ GIT_DIR=/path/to/repo.git GIT_WORK_DIR=../.. git add a
If the user is going to work in the working tree for extended period of time, cd'ing around and running multiple git commands:
$ GIT_DIR=/path/to/repo.git; export GIT_DIR
$ git foo ; git bar ; cd subdir ; git baz ; ...And without $GIT_DIR/workdir support, perhaps the user would do:
$ GIT_DIR=/path/to/repo.git; export GIT_DIR
$ GIT_WORK_DIR=$(pwd)/../..; export GIT_WORK_DIR
$ git foo ; git bar ; cd subdir ; git baz ; ...What I am getting at is that I personally feel that --git-dir= option is already an unnecessary redundancy that is there only to confuse new people by having more than one way to do the same thing, and --work-dir= option seems to be only adding to the same confusion. Do we really want that as an option?
Re: [PATCH] git-init: set up GIT_DIR/workdir if GIT_WORK_DIR is set
Quoted 5 lines · Junio C Hamano
Quoted 3 lines · Matthias Lederhofer
I just thought that
GIT_WORK_DIRshould be relative to the current working directory because it's more intuitive, e.g.
Quoted 8 lines
Quoted 4 lines
$ git --git-dir=/path/to/repo.git --work-dir=../.. add awhere ../.. matches the path to the toplevel working directory from cwd. But this definitely is annoying when changing directories.
Not so fast. That was a trick suggestion, only meant to see if you have thought through the issues, and you did not have to agree with me so quickly ;-).
Well, I have no strong feelings for either handling because I'll probably always use pwd/relative/path anyway.
Is there anything more to this decision than this?
GIT_WORK_DIR relative to cwd:
git --work-dir <path> [..] is more intuitive
GIT_WORK_DIR relative to $GIT_DIR:
$GIT_DIR/workdir and $GIT_WORK_DIR are interpreted exactly the same way, which primarily makes it easier to implement git init with --work-dir :-)
Quoted 4 lines
By the way, I do not find your command line example intuitive at all, whether the --work-dir= parameter is relative or absolute. Do you honestry expect that loooong command line is something people would use in real life?
For one-shot things I prefer --git-dir and --work-dir over GIT_DIR and GIT_WORK_DIR because they are lowercase and for GIT_WORK_DIR it's even shorter; and all the examples were one-shot things (well, one used the same --git-dir twice).
[PATCH(amend)] git-init: set up GIT_DIR/workdir if GIT_WORK_DIR is set
In reply to Matthias Lederhofer---
It's much easier when $GIT_WORK_DIR is always interpreted relative to $GIT_DIR.
--- builtin-init-db.c | 14 +++++++++++++- 1 files changed, 13 insertions(+), 1 deletions(-)
builtin-init-db.c +13 -1
@@ -182,6 +182,7 @@ static int create_default_files(const char *git_dir, const char *template_path)char repo_version_string[10 ];int reinit;int filemode; +const char *gitwd =getenv (GIT_WORKING_DIR_ENVIRONMENT );if (len >sizeof (path)-50 )die ("insane git directory %s" , git_dir);
@@ -252,10 +253,21 @@ static int create_default_files(const char *git_dir, const char *template_path) }git_config_set ("core.filemode" , filemode ?"true" :"false" ); -if (is_bare_repository ()) { +if (is_bare_repository () && !gitwd) {git_config_set ("core.bare" ,"true" ); }else { +if (gitwd) { +FILE *fp =NULL ; + + path[len] =0 ; +strcpy (path + len,"workdir" ); +if (!(fp =fopen (path,"w" ))) +die ("Cannot open GIT_DIR/workdir" ); +fprintf (fp,"%s\n" , gitwd); +fclose (fp); + } +git_config_set ("core.bare" ,"false" );/* allow template config file to override the default */ if (log_all_ref_updates ==-1 )
Signature · 1 line
1.5.0.3.1007.g7ff7
Quoted 3 lines · Matthias Lederhofer
Missing:
Documentation update but if this feature should not get accepted.. therefore I'll wait for feedback first.
Did I say something about a comment like this in the past? But I'll let this pass this time...
Quoted 8 lines
Idea:
Add some way to configure tho working directory for one repository and setGIT_WORK_DIRautomatically whenGIT_DIRis used. I think of:
* a subdirectory in the repository directory
e.g. .git/work_dir which is supposed to be a symlink (or a textfile containing the path for windows compatibility?)
or
* a configuration variable
I am not sure why you bother. Obviously I am missing a few useful use cases you and Nguyen have in mind.
One very typical use of GIT_DIR to have the repository somewhere other than the usual $GIT_TOP_DIR/.git is to do an initial import from an extracted tarball into a bare repository (and then wipe away the temporary directory that contains extracted tarball), and that use case I understand well.
But either .git/work_dir or a configuration means you are linking a repository with a _single_ working tree, permanently. If you are permanently linking one repository with a _single_ working tree, is it too much bother to have that repository at the usual $GIT_TOP_DIR/.git like everybody else?
If storage space is the issue, then doing
$ln -s $else_where/.git .git
would be sufficient.
What's the real motivation behind all this?
I've heard read-only working tree in the past, but that cannot be it. If the working tree is read-only and if you are telling git to always use that read-only working tree when using that particular repository, what useful git operations are you doing while in that working tree?
Quoted 1 line · Junio C Hamano
What's the real motivation behind all this?
Coincidentally, I found I was needing this feature just yesterday.
I wanted to keep random configuration files in a repository. I didn't want the directory structure though. The config files are, of course, in my home directory, however I didn't want the danger of putting a .git that low in my hierarchy. Having a .git that is findable from any location in my tree seems a bad idea.
So; I put the repository somewhere else and set GIT_DIR. However that scuppered my plans. Trying to add a config file results in "not in a working directory" (of course), because even though git can find the repository, it has no way of knowing which directory to consider as the root of the working tree.
Let me put this in command form for you:
$ cd $HOME $ export GIT_DIR=$HOME/gitrepos $ git init $ git add .bashrc fatal: add must be run in a work tree
Being able to set GIT_WORKING_DIR would have let me do this.
Andy
Signature · 2 lines
Dr Andy Parkins, M Eng (hons), MIET [email protected]
Quoted 10 lines · Junio C Hamano
Quoted 8 lines · Matthias Lederhofer
Idea:
Add some way to configure tho working directory for one repository and setGIT_WORK_DIRautomatically whenGIT_DIRis used. I think of:
* a subdirectory in the repository directory
e.g. .git/work_dir which is supposed to be a symlink (or a textfile containing the path for windows compatibility?)
or
* a configuration variable
Quoted 2 lines
I am not sure why you bother. Obviously I am missing a few useful use cases you and Nguyen have in mind.
For example have the checkout of a git repository publicly available (e.g. on a webserver). The .git directory containing all the history should probably not go there (especially if it tracks scripts). Sure, setting strict permissions solves this too in most cases but anyway it's nice to have the option to move the repository away.
Additionally when reading the man page about GIT_DIR it says 'the default value is .git', which sounds a bit like "hey, if you don't like the name you're free to change it", but as soon as you change it you run into problems because git behaves strange in subdirectories :)
Quoted 2 lines
But either .git/work_dir or a configuration means you are linking a repository with a _single_ working tree, permanently.
Well, this would only be the default value for convenience with GIT_WORK_DIR/--work-dir still overriding this value. You'd only have to set GIT_DIR=~/src/website and work on the website without setting the second environment variable too.
Quoted 5 lines
I've heard read-only working tree in the past, but that cannot be it. If the working tree is read-only and if you are telling git to always use that read-only working tree when using that particular repository, what useful git operations are you doing while in that working tree?
The tools to inspect (git diff, ..) and track (git add, ..) work fine. So one could easily (without copying stuff around) track changes of a read-only directory.
Quoted 5 lines · Matthias Lederhofer
For example have the checkout of a git repository publicly available (e.g. on a webserver). The .git directory containing all the history should probably not go there (especially if it tracks scripts). Sure, setting strict permissions solves this too in most cases but anyway it's nice to have the option to move the repository away.
That's fine. Will you constantly work inside that webserver exposed working tree, though? I suspect the operation you would do there would only be "GIT_DIR=/some/where/else git checkout -f" to refresh the published copy, so I do not think even GIT_WORK_DIR is needed for that use case (just to make sure, I am not opposed to having GIT_WORK_DIR -- my "why bother" is about having the equivalent in .git/work_dir or .git/config).
Quoted 4 lines
Additionally when reading the man page about
GIT_DIRit says 'the default value is .git', which sounds a bit like "hey, if you don't like the name you're free to change it", but as soon as you change it you run into problems because git behaves strange in subdirectories :)
That is really a historical mention. The current Porcelain-ish depend on that "default" layout (I know you know that after seeing what setup_git_directory does), and I think GIT_DIR should not be taught to new people as such.
Quoted 3 lines
The tools to inspect (git diff, ..) and track (git add, ..) work fine. So one could easily (without copying stuff around) track changes of a read-only directory.
Why does read-only directory have changes to begin with???
Hi,
Quoted 1 line · Junio C Hamano
Why does read-only directory have changes to begin with???
Tracking (parts of) /etc/, I change as root, but commit as another user (to prevent accidental corruption).
Ciao,
Dscho
Quoted 10 lines · Junio C Hamano
Quoted 8 lines · Matthias Lederhofer
Idea:
Add some way to configure tho working directory for one repository and setGIT_WORK_DIRautomatically whenGIT_DIRis used. I think of:
* a subdirectory in the repository directory
e.g. .git/work_dir which is supposed to be a symlink (or a textfile containing the path for windows compatibility?)
or
* a configuration variable
Quoted 2 lines
I am not sure why you bother. Obviously I am missing a few useful use cases you and Nguyen have in mind.
I actually like this feature. Let me explain why I think it's a great feature:
Quoted 5 lines
But either .git/work_dir or a configuration means you are linking a repository with a _single_ working tree, permanently. If you are permanently linking one repository with a _single_ working tree, is it too much bother to have that repository at the usual $GIT_TOP_DIR/.git like everybody else?
I'll tell you why: it makes tons of sense to have the git repository linked to exactly one working tree, *but the reverse is not necessarily always true*!
In other words, it can be a 1:n relationship.
You can have one working tree that is related to *multiple* git repositories.
That sounds insane, but I actually think it works, and makes tons of sense. Think something as simple as your own home directory.
It's possible that you want to track your music collection with git, but say that your music collection is a few different subdirectories or files in your home directory: maybe you track your "Music" directory (which contains the actual mp3 files or whatever), but maybe you'd like the same repository to *also* track things like your configuration file for whatever mp3-player you're using (".xmms"? Whatever).
So let's say that you have a git repository for tracking all that. The "working tree" for that git repository would be your home directory.
Now, imagine that you *also* want to track something else in git, that you *also* have in your home directory. Say your ".bashrc" files etc. They have nothing to do with your music tracking setup, so you don't want to track it in the same git repository, and you want to have a totally different .git/index file for those. But again, the *working*tree* is actually your home directory.
So allowing you to set the working tree associated with a particular git repository actually solves that problem. They can both share the same working tree (you'd want to track disjunct parts of the working tree, of course), which means that the working tree obviously does *not* want to have a .git/ directory in it. And to track your music changes, you'd just do
cd music-repository
git add music/
git commit
to add any new files, and you'd be all set (or something like this).
There are other cases than just your home directory where you might want to track disjoint filesets in different git repositories. Things like /etc fall under the same "many unrelated things in the same working tree" setup.
So I actually think it makes tons of sense to allow a way to set the working tree for a git repository, and go the other way.
Linus
Quoted 9 lines · Linus Torvalds
So let's say that you have a git repository for tracking all that. The "working tree" for that git repository would be your home directory.
Now, imagine that you *also* want to track something else in git, that you *also* have in your home directory. Say your ".bashrc" files etc. They have nothing to do with your music tracking setup, so you don't want to track it in the same git repository, and you want to have a totally different .git/index file for those. But again, the *working*tree* is actually your home directory.
That is a good example usage schenario; we would need to think about what to do with .gitignore (and .gitattributes if we will have that in-tree), though.
Quoted 12 lines · Junio C Hamano
Quoted 9 lines · Linus Torvalds
So let's say that you have a git repository for tracking all that. The "working tree" for that git repository would be your home directory.
Now, imagine that you *also* want to track something else in git, that you *also* have in your home directory. Say your ".bashrc" files etc. They have nothing to do with your music tracking setup, so you don't want to track it in the same git repository, and you want to have a totally different .git/index file for those. But again, the *working*tree* is actually your home directory.
Quoted 3 lines
That is a good example usage schenario; we would need to think about what to do with .gitignore (and .gitattributes if we will have that in-tree), though.
Modulo problems like above, isn't this just a solid solution to the
modules problem? (not only directory-level modules, but intertwined
(in the sense of repositories) files within a directory).
And wouldn't the cheap hack just to be to have a pecking order for determining attributes? (i.e. a master file with metadata which is owned by the working directory, not the repository, to decide which repository to look at for which files).
Ouch, but Junio's right, it's still painful, ugly and problematic.
best,
-tony
[email protected]
Muttenz, Switzerland.
"Commit early,commit often, and commit in a repository from which we can easily roll-back your mistakes" (AJR, 4Jan05).
Quoted 4 lines · Junio C Hamano
That is a good example usage schenario; we would need to think about what to do with .gitignore (and .gitattributes if we will have that in-tree), though.
Good point. That's a real problem.
I guess you could say that for this kind of usage scenario you only want to use the per-repository .git/ignore file, or maybe have some way of specifying the name of the .gitignore file per repository.
Hmm. I'm not sure it was a great idea. I still like the concept, but you're right, it's not without its problems.
Linus
setup.c const char *setup_git_directory_gently(int *nongit_ok) · line 228
Quoted 3 lines · Matthias Lederhofer
setup.c +2
-0+ gitwd =getenv (GIT_WORKING_DIR_ENVIRONMENT ); +if (!gitwd ||stat (gitwd, &st_work))return NULL ;
I propose the following instead of the last two lines:
if (!gitwd)
return NULL;
if (stat(gitwd, &st_work))
die("Unable to stat git working directory %s",gitwd);Quoted 14 lines
setup.c +14
-0+if (inside_git_dir ==-1 &&stat (gitdirenv, &st_git)) +die ("Unable to stat git directory" ); +if (!getcwd (cwd,sizeof (cwd)-1 ) || cwd[0 ] !='/' ) +die ("Unable to read current working directory" ); + len =strlen (cwd); + + prefix = cwd+len; +for (;;) { + c = *prefix; + *prefix ='\0' ; +if (stat (cwd, &st)) +die ("Unable to stat '%s'" , cwd); +if (st_work.st_dev == st.st_dev && + st_work.st_ino == st.st_ino)
setup.c const char *setup_git_directory_gently(int *nongit_ok) · line 252
Quoted 10 lines
setup.c +10
-0+break ; +if (inside_git_dir ==-1 && + st_git.st_dev == st.st_dev && + st_git.st_ino == st.st_ino) + inside_git_dir =1 ; + *prefix = c; + +if (prefix == cwd+1 ) { + has_working_directory =0 ; +return NULL ;
My case seems a bit complicated than usual. The working directory (/home/pclouds/blog/data) was not a prefix of cwd (/home/pclouds/blog) so the code failed silently at this line. If I replace "has_working_directory = 0; return NULL;" with "strcpy(cwd,gitwd);c = 0;break;", it may work but see below
setup.c const char *setup_git_directory_gently(int *nongit_ok) · line 262
Quoted 10 lines
setup.c +10
-0+ } +while (*(--prefix) !='/' ) + ;/* do nothing */ +if (prefix == cwd) + prefix++; + } + +if (chdir (cwd)) +die ("Cannot change directory to '%s'" , cwd); +
If cwd changed and GIT_DIR is a relative path, git can no longer access GIT_DIR properly.
Signature · 1 line
Duy
Quoted 5 lines · Nguyen Thai Ngoc Duy
My case seems a bit complicated than usual. The working directory (
/home/pclouds/blog/data) was not a prefix of cwd (/home/pclouds/blog) so the code failed silently at this line. If I replace "has_working_directory= 0; return NULL;" with "strcpy(cwd,gitwd);c = 0;break;", it may work but see below
If you're outside the specifed working directory the is_bare_repository will return true, just as if you don't have a working directory. Do you expect anything else or doesn't this work?
Quoted 10 lines · Matthias Lederhofer
Quoted 5 lines · Nguyen Thai Ngoc Duy
My case seems a bit complicated than usual. The working directory (
/home/pclouds/blog/data) was not a prefix of cwd (/home/pclouds/blog) so the code failed silently at this line. If I replace "has_working_directory= 0; return NULL;" with "strcpy(cwd,gitwd);c = 0;break;", it may work but see belowIf you're outside the specifed working directory the
is_bare_repositorywill return true, just as if you don't have a working directory. Do you expect anything else or doesn't this work?
Yes I expected it to move the specified working directory as described in the previous mail (copied/pasted below). However the patch requires me to be in workdir somewhere already (which is fine if that is your expectation). If that's the case, maybe you should tell users something about GIT_WORK_DIR not applicable.
Quoted 8 lines
Quoted 3 lines · Nguyen Thai Ngoc Duy
By the way, is it plausible to add --git-workdir option to specify working directory? With that option, I won't need to _chdir_ to the working directory, run git commands and
_chdirback_.http://article.gmane.org/gmane.comp.version-control.git/38382
Since I did not need this feature that much and no one replied that there is any interest I did not look any further into it.
Signature · 1 line
Duy
Quoted 5 lines · Nguyen Thai Ngoc Duy
Yes I expected it to move the specified working directory as described in the previous mail (copied/pasted below). However the patch requires me to be in workdir somewhere already (which is fine if that is your expectation). If that's the case, maybe you should tell users something about
GIT_WORK_DIRnot applicable.
Let's say we have GIT_DIR=/tmp/git GIT_WORK_DIR=/tmp/foo and are in /tmp. You want git add bar to chdir to /tmp/foo and add the file bar from /tmp/foo?
Quoted 4 lines
Quoted 4 lines
Quoted 3 lines · Nguyen Thai Ngoc Duy
By the way, is it plausible to add --git-workdir option to specify working directory? With that option, I won't need to _chdir_ to the working directory, run git commands and
_chdirback_.
I thought you meant the chdir to the toplevel directory when you're in a subdirectory. For this case I'd rather suggest
mygit() {
old=$(pwd)
cd "$MYTOPDIR"
git "$@"
ret=$?
cd "$old"
return $ret
}Quoted 10 lines · Matthias Lederhofer
Quoted 5 lines · Nguyen Thai Ngoc Duy
Yes I expected it to move the specified working directory as described in the previous mail (copied/pasted below). However the patch requires me to be in workdir somewhere already (which is fine if that is your expectation). If that's the case, maybe you should tell users something about
GIT_WORK_DIRnot applicable.Let's say we have GIT_DIR=/tmp/git GIT_WORK_DIR=/tmp/foo and are in /tmp. You want
git add barto chdir to/tmp/fooand add the file bar from/tmp/foo?
Yes. I wanted it for easy scripting but it's not very intuitive from command line. I'd take it back.
Quoted 7 lines
Quoted 5 lines
Quoted 5 lines
Quoted 3 lines · Nguyen Thai Ngoc Duy
By the way, is it plausible to add --git-workdir option to specify working directory? With that option, I won't need to _chdir_ to the working directory, run git commands and
_chdirback_.I thought you meant the chdir to the toplevel directory when you're in a subdirectory. For this case I'd rather suggest
Quoted 9 lines
mygit() {
old=$(pwd)
cd "$MYTOPDIR"
git "$@"
ret=$?
cd "$old"
return $ret
}Thanks, will try
Signature · 1 line
Duy
This environment variable can be used with GIT_DIR to specify the toplevel working directory. When GIT_DIR is not set this variable is ignored. As for GIT_DIR there is also the option git --work-dir which overrides the environment variable.
---
New patch, this should go with the 'rev-parse --is-bare-repository option' patch.
Documentation added, is_bare_repository check fixed, relative GIT_DIR fix. Becaus GIT_DIR is expanded to a full path setup_git_env should be called after setup_git_directory_gently. I searched for the callers of setup_git_directory_gently and think this is fulfilled.
Quoted 6 lines · Nguyen Thai Ngoc Duy
I propose the following instead of the last two lines:
if (!gitwd) return NULL; if (stat(gitwd, &st_work)) die("Unable to stat git working directory %s",gitwd);
It's in this new patch.
Quoted 2 lines
If cwd changed and
GIT_DIRis a relative path, git can no longer accessGIT_DIRproperly.
This too.
--- Documentation/git.txt | 16 ++++++++- cache.h | 2 + environment.c | 11 +++++- git.c | 12 ++++++- setup.c | 92 +++++++++++++++++++++++++++++++++++++++++++----- 5 files changed, 119 insertions(+), 14 deletions(-)
Documentation/git.txt +15 -1
@@ -10,7 +10,8 @@ SYNOPSIS -------- [verse] 'git' [--version] [--exec-path[=GIT_EXEC_PATH]] [-p|--paginate] - [--bare] [--git-dir=GIT_DIR] [--help] COMMAND [ARGS] + [--bare] [--git-dir=GIT_DIR] [--work-dir=GIT_WORK_DIR] + [--help] COMMAND [ARGS] DESCRIPTION -----------
@@ -81,6 +82,13 @@ OPTIONS Set the path to the repository. This can also be controlled by setting the GIT_DIR environment variable. +--work-dir=<path>:: + Set the path to the toplevel working directory. The value will + be used only in combination with $GIT_DIR or '--git-dir'. + Without this option git will assume that the current directory + is also the toplevel directory. This can also be controlled by + setting the GIT_WORK_DIR environment variable. + --bare:: Same as --git-dir=`pwd`.
@@ -325,6 +333,12 @@ git so take care if using Cogito etc. specifies a path to use instead of the default `.git` for the base of the repository. +'GIT_WORK_DIR':: + Set the path to the toplevel working directory. The value will + be used only in combination with $GIT_DIR or '--git-dir'. + Without this environment variable git will assume that the + current directory is also the toplevel directory. + git Commits ~~~~~~~~~~~ 'GIT_AUTHOR_NAME'::
cache.h +2 -0
@@ -144,6 +144,7 @@ enum object_type { };#define GIT_DIR_ENVIRONMENT "GIT_DIR" +#define GIT_WORKING_DIR_ENVIRONMENT "GIT_WORK_DIR"#define DEFAULT_GIT_DIR_ENVIRONMENT ".git"#define DB_ENVIRONMENT "GIT_OBJECT_DIRECTORY"#define INDEX_ENVIRONMENT "GIT_INDEX_FILE"
@@ -164,6 +165,7 @@ extern char *get_graft_file(void);#define ALTERNATE_DB_ENVIRONMENT "GIT_ALTERNATE_OBJECT_DIRECTORIES" +extern int has_working_directory;extern const char **get_pathspec (const char *prefix,const char **pathspec);extern const char *setup_git_directory_gently (int *);extern const char *setup_git_directory (void );
environment.c +9 -2
@@ -59,8 +59,15 @@ static void setup_git_env(void)int is_bare_repository (void ) {const char *dir, *s; -if (0 <= is_bare_repository_cfg) -return is_bare_repository_cfg; +/* definitely bare */ +if (is_bare_repository_cfg ==1 ) +return 1 ; +/* GIT_WORK_DIR is set, bare if cwd is outside */ +if (has_working_directory >=0 ) +return !has_working_directory; +/* configuration says it is not bare */ +if (is_bare_repository_cfg ==0 ) +return 0 ; dir =get_git_dir ();if (!strcmp (dir,DEFAULT_GIT_DIR_ENVIRONMENT ))
git.c +11 -1
@@ -4,7 +4,7 @@#include "quote.h" const char git_usage_string[] = -"git [--version] [--exec-path[=GIT_EXEC_PATH]] [-p|--paginate] [--bare] [--git-dir=GIT_DIR] [--help] COMMAND [ARGS]" ; +"git [--version] [--exec-path[=GIT_EXEC_PATH]] [-p|--paginate] [--bare] [--git-dir=GIT_DIR] [--work-dir=GIT_WORK_DIR] [--help] COMMAND [ARGS]" ;static void prepend_to_path (const char *dir,int len) {
@@ -68,6 +68,16 @@ static int handle_options(const char*** argv, int* argc) (*argc)--; }else if (!prefixcmp (cmd,"--git-dir=" )) {setenv (GIT_DIR_ENVIRONMENT , cmd +10 ,1 ); + }else if (!strcmp (cmd,"--work-dir" )) { +if (*argc <2 ) { +fprintf (stderr,"No directory given for --work-dir.\n" ); +usage (git_usage_string); + } +setenv (GIT_WORKING_DIR_ENVIRONMENT , (*argv)[1 ],1 ); + (*argv)++; + (*argc)--; + }else if (!prefixcmp (cmd,"--work-dir=" )) { +setenv (GIT_WORKING_DIR_ENVIRONMENT , cmd +11 ,1 ); }else if (!strcmp (cmd,"--bare" )) {static char git_dir[PATH_MAX +1 ];setenv (GIT_DIR_ENVIRONMENT ,getcwd (git_dir,sizeof (git_dir)),1 );
setup.c +82 -10
110 lines not on this page · raw message
Signature · 1 line
1.5.0.3.356.gafc9e-dirty
PATCH 1/1 use $GIT_DIR/workdir as working directory with $GIT_DIR
$GIT_DIR/workdir will be used as fallback if $GIT_WORK_DIR is not set
--- Documentation/repository-layout.txt | 4 ++ setup.c | 64 ++++++++++++++++++++++++++++++++--- 2 files changed, 63 insertions(+), 5 deletions(-)
Documentation/repository-layout.txt +4 -0
@@ -179,3 +179,7 @@ shallow:: and maintained by shallow clone mechanism. See `--depth` option to gitlink:git-clone[1] and gitlink:git-fetch[1]. +workdir:: + Directory to be used as toplevel working directory when GIT_DIR + is set. If this is a file the first line will be used as the + name of the directory. This can be overriden by GIT_WORK_DIR.
setup.c +59 -5
83 lines not on this page · raw message
Signature · 1 line
1.5.0.3.357.g0b2cd
PATCH 1/1 core.workdir config variable
core.workdir is used as default value for $GIT_WORK_DIR
---
This one replaces the 'use $GIT_DIR/workdir as working directory with $GIT_DIR' patch and uses core.workdir instead. This patch gets core.workdir only for setup.c from the configuration file. Perhaps this should be handled in git_default_config like most other core.* variables.
I just noticed that dying if the specified workdir is invalid can cause trouble too:
$ export GIT_DIR=/path/to/repository
$ git config core.workdir /non-existent
$ git config core.workdir ../workdir
fatal: Unable to stat git working directory '/non-existent'Workaround is either to edit the file manually or do:
$ git --work-dir=. config core.workdir ../workdir
--- Documentation/config.txt | 4 +++ setup.c | 53 +++++++++++++++++++++++++++++++++++++++++---- 2 files changed, 52 insertions(+), 5 deletions(-)
Documentation/config.txt +4 -0
@@ -162,6 +162,10 @@ repository that ends in "/.git" is assumed to be not bare (bare = false), while all other repositories are assumed to be bare (bare = true). +core.workdir:: + Directory to be used as toplevel working directory when GIT_DIR + is set. This can be overriden by GIT_WORK_DIR. + core.logAllRefUpdates:: Updates to a ref <ref> is logged to the file "$GIT_DIR/logs/<ref>", by appending the new and old
setup.c +48 -5
72 lines not on this page · raw message
Signature · 1 line
1.5.0.3.970.ge984-dirty
[PATCH(amend)] core.workdir config variable
core.workdir is used as default value for $GIT_WORK_DIR
---
Sorry, the last one was totally broken. Testing without recompiling isn't good..
--- Documentation/config.txt | 4 +++ setup.c | 53 +++++++++++++++++++++++++++++++++++++++++---- 2 files changed, 52 insertions(+), 5 deletions(-)
Documentation/config.txt +4 -0
@@ -162,6 +162,10 @@ repository that ends in "/.git" is assumed to be not bare (bare = false), while all other repositories are assumed to be bare (bare = true). +core.workdir:: + Directory to be used as toplevel working directory when GIT_DIR + is set. This can be overriden by GIT_WORK_DIR. + core.logAllRefUpdates:: Updates to a ref <ref> is logged to the file "$GIT_DIR/logs/<ref>", by appending the new and old
setup.c +48 -5
72 lines not on this page · raw message
Signature · 1 line
gitgui.0.6.3.g4bccd
Re: [PATCH(amend)] core.workdir config variable
Quoted 1 line · Matthias Lederhofer
core.workdir is used as default value for $GIT_WORK_DIR
...
Quoted 2 lines
Signature · 1 line
gitgui.0.6.3.g4bccd
Really? gitgui generates emails now? ;-)
Matthias, your git binaries were built with an older (pre 1.5.0) git-describe in the path. This caused the version number to be incorrectly determined, due to an old bug in git-describe.
Recompiling with your "gitgui.0.6.3" git-describe should get the correct version number, as that is most definately after the git-describe bug fix.
Signature · 1 line
Shawn.
Re: [PATCH(amend)] core.workdir config variable
Quoted 7 lines · Shawn O. Pearce
Quoted 1 line · Matthias Lederhofer
core.workdir is used as default value for $GIT_WORK_DIR
...
Quoted 2 lines
Signature · 1 line
gitgui.0.6.3.g4bccdReally? gitgui generates emails now? ;-)
It might not be a bad idea actually. You let people make commits. Why not let them pick commits, run format-patch and drive send-email for them from the UI?
Re: [PATCH(amend)] core.workdir config variable
Quoted 5 lines · Junio C Hamano
Quoted 3 lines · Shawn O. Pearce
Quoted 1 line · Matthias Lederhofer
core.workdir is used as default value for $GIT_WORK_DIR
...
Quoted 8 lines
Quoted 4 lines
Quoted 2 lines
Signature · 1 line
gitgui.0.6.3.g4bccdReally? gitgui generates emails now? ;-)
It might not be a bad idea actually. You let people make commits. Why not let them pick commits, run format-patch and drive send-email for them from the UI?
No, its not. There's a lot of stuff I want to put into there; that just happens to be one of them. ;-)
Signature · 1 line
Shawn.
Quoted 7 lines · Matthias Lederhofer
This environment variable can be used with
GIT_DIRto specify the toplevel working directory. WhenGIT_DIRis not set this variable is ignored. As forGIT_DIRthere is also the option git --work-dir which overrides the environment variable.Signed-off-by Matthias Lederhofer <[email protected]>
Works for me.
Signature · 1 line
Duy
environment.c int is_bare_repository(void) · line 68
Quoted 13 lines · Matthias Lederhofer
environment.c +2
-0@@ -61,6 +61,8 @@ int is_bare_repository(void)const char *dir, *s;if (0 <= is_bare_repository_cfg)return is_bare_repository_cfg; +if (0 <= has_working_directory) +return !has_working_directory; dir =get_git_dir ();if (!strcmp (dir,DEFAULT_GIT_DIR_ENVIRONMENT ))
Um.. git-sh-setup.sh may need special treatment because its is_bare_directory doesn't call this function.
Signature · 1 line
Duy
PATCH 1/1 rev-parse: --is-bare-repository option
---
Quoted 2 lines · Nguyen Thai Ngoc Duy
Um..
git-sh-setup.shmay need special treatment because itsis_bare_directorydoesn't call this function.
Here is rev-parse --is-bare-repository to fix this.
I'm not sure if git-sh-setup.sh:is_bare_repository should do other checks if git-rev-parse --is-bare-repository fails.
--- Documentation/git-rev-parse.txt | 7 +++++++ builtin-rev-parse.c | 5 +++++ git-sh-setup.sh | 6 +----- git-svn.perl | 2 +- 4 files changed, 14 insertions(+), 6 deletions(-)
Documentation/git-rev-parse.txt +7 -0
@@ -89,6 +89,13 @@ OPTIONS --git-dir:: Show `$GIT_DIR` if defined else show the path to the .git directory. +--is-inside-git-dir:: + When the current working directory is below the repository + directory print "true", otherwise "false". + +--is-bare-repository:: + When the repository is bare print "true", otherwise "false". + --short, --short=number:: Instead of outputting the full SHA1 values of object names try to abbreviate them to a shorter unique name. When no length is specified
builtin-rev-parse.c +5 -0
@@ -352,6 +352,11 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix) : "false");continue ; } +if (!strcmp (arg,"--is-bare-repository" )) { +printf ("%s\n" ,is_bare_repository () ?"true" + :"false" ); +continue ; + }if (!prefixcmp (arg,"--since=" )) {show_datestring ("--max-age=" , arg+8 );continue ;
git-sh-setup.sh +1 -5
@@ -29,11 +29,7 @@ set_reflog_action() { } is_bare_repository () { - git-config --bool --get core.bare || - case "$GIT_DIR" in - .git | */.git) echo false ;; - *) echo true ;; - esac + git-rev-parse --is-bare-repository } cd_to_toplevel () {
git-svn.perl +1 -1
@@ -559,7 +559,7 @@ sub post_fetch_checkout { my $index = $ENV{GIT_INDEX_FILE} || "$ENV{GIT_DIR}/index"; return if -f $index; - chomp(my $bare = `git config --bool --get core.bare`); + chomp(my $bare = `git rev-parse --is-bare-repository`); return if $bare eq 'true'; return if command_oneline(qw/rev-parse --is-inside-git-dir/) eq 'true'; command_noisy(qw/read-tree -m -u -v HEAD HEAD/);
Signature · 1 line
1.5.0.3.355.g8488f-dirty
Quoted 3 lines · Junio C Hamano
That is a good example usage schenario; we would need to think about what to do with .gitignore (and .gitattributes if we will have that in-tree), though.
While it's not solveable yet; if git gets gitattributes support, then it's easy. As long as there is a way of specifying attributes in the config (which I'm sure there will be), in the music repository you would have (syntax being made up on the spot)
[attribute "gitattributesfile"]
path = .gitattribute-music
[attribute "gitignorefile"]
path = .gitignore-music
Then in the config repository:
[attribute "gitattributesfile"]
path = .gitattribute-config
[attribute "gitignorefile"]
path = .gitignore-config
Andy
Signature · 2 lines
Dr Andy Parkins, M Eng (hons), MIET [email protected]