threads / discuss / 17281

how to git a read only directory

Subject: how to git a read only directory

## tl;dr

10 messages between Jan 21, 2009 and Jan 22, 2009.

replies: 9people: 3as markdown or json

bill lam· Jan 21, 2009, 08:33 UTC · lore

I want to use git to keep track of files inside /etc but do not want to do it as a super user. Is that possible to put GIT_DIR under my home directory and add public-read files inside /etc? Or that it could be done in some other ways.

Thanks.
-- 
regards,
====================================================
GPG key 1024D/4434BAB3 2008-08-24
gpg --keyserver subkeys.pgp.net --recv-keys 4434BAB3
唐詩164 張喬  書邊事
    調角斷清秋  征人倚戍樓  春風對青塚  白日落梁州
    大漠無兵阻  窮邊有客遊  蕃情似此水  長願向南流
Michael J Gruber· Jan 21, 2009, 09:57 UTC · re: bill lam · lore

Re: how to git a read only directory

bill lam venit, vidit, dixit 21.01.2009 09:33:
Show 7 quoted lines
> I want to use git to keep track of files inside /etc but do not want
> to do it as a super user. Is that possible to put GIT_DIR under my
> home directory and add public-read files inside /etc? Or that it could
> be done in some other ways.
> 
> Thanks.
> 

You can use the core.worktree config variable in order to specify a worktree (/etc) which is not directly above .git. For your git commands to find the .git dir you would need to set GIT_DIR or use the --git-dir parameter.

I have found, though, that several git commands require you to be within the worktree or else they become confused. I use a shell function for that, doing something like "gg ~/path/project log" which requires ~/path/project.git to have its core.worktree set. Also, having a git alias like "git view" set up for gitk helps calling gitk in that way. git-gui makes unfounded assumptions and is completely unhappy in a situation like that.

I think the situation around GIT_DIR and and worktree is a bit in the flux at the moment (panta rhei..) but it works for me.

Cheers, Michael

Here's the "git go" bash function. I'm not proud of it, it makes several assumptions and does no error checking. Use it like "gg path/project command parameters" if the git-dir is "path/project.git" or "gg path/project/" if the git-dir is "path/project/.git". Have your core.worktree set in the former case, and also in the latter if the worktree is not "path/project".

I'm sure it can be done much better using helper functions from git's bash-completion, e.g.

gg ()
{
    local _gg="$1";
    shift;
    local _ggwt=`git --git-dir="${_gg}.git" config --get core.worktree`;
    if [ -z "${_ggwt}" ]; then
        _ggwt=$(cd ${_gg} 2> /dev/null && pwd -P);
    fi;
    local _gggd=$(cd ${_gg}.git 2> /dev/null && pwd -P);
    pushd ${_ggwt} > /dev/null;
    git --git-dir=${_gggd} "$@";
    popd > /dev/null
}
bill lam· Jan 21, 2009, 15:48 UTC · re: Michael J Gruber · lore

Re: how to git a read only directory

On Wed, 21 Jan 2009, Michael J Gruber wrote:
> You can use the core.worktree config variable in order to specify a
> worktree (/etc) which is not directly above .git. For your git commands
> to find the .git dir you would need to set GIT_DIR or use the --git-dir
> parameter.
Michael, thanks for pointing out worktree being the trick to use.
-- 
regards,
====================================================
GPG key 1024D/4434BAB3 2008-08-24
gpg --keyserver subkeys.pgp.net --recv-keys 4434BAB3
唐詩267 王翰  涼州詞
    葡萄美酒夜光杯  欲飲琵琶馬上催  醉臥沙場君莫笑  古來征戰幾人回
Boaz Harrosh· Jan 21, 2009, 12:34 UTC · re: bill lam · lore

Re: how to git a read only directory

bill lam wrote:
Show 7 quoted lines
> I want to use git to keep track of files inside /etc but do not want
> to do it as a super user. Is that possible to put GIT_DIR under my
> home directory and add public-read files inside /etc? Or that it could
> be done in some other ways.
> 
> Thanks.
> 
I did the really easy hack (on my /etc BTW) and it worked fine for me.

I created a master project folder under ~home, init a new git repo, then symlink /etc/ onto an etc/ in the project dir, added all etc/ files. I like the extra a/etc/fstab in the patch files better then a/fstab.

And it is a life saver, payed it's effortless in gold. Some shining new distro should come up with a git based management system and it will leave all the other distros in the dust.

Cheers Boaz

bill lam· Jan 21, 2009, 15:52 UTC · re: Boaz Harrosh · lore

Re: how to git a read only directory

On Wed, 21 Jan 2009, Boaz Harrosh wrote:
> I created a master project folder under ~home, init a new git repo,
> then symlink /etc/ onto an etc/ in the project dir, added all etc/
> files. I like the extra a/etc/fstab in the patch files better then
> a/fstab.

I create a symlink in ~/gitrepo/etc to /etc and git init an empty repo there. However it failed in symlink when I tried to add files. Could you give more detail how to do it? Meanwhile I use worktree method as suggested by Michael.

-- 
regards,
====================================================
GPG key 1024D/4434BAB3 2008-08-24
gpg --keyserver subkeys.pgp.net --recv-keys 4434BAB3
唐詩205 元稹  遣悲懷三首之一
    謝公最小偏憐女  自嫁黔婁百事乖  顧我無衣搜藎篋  泥他沽酒拔金釵
    野蔬充膳甘長藿  落葉添薪仰古槐  今日俸錢過十萬  與君營奠復營齋
Boaz Harrosh· Jan 21, 2009, 16:46 UTC · re: bill lam · lore

Re: how to git a read only directory

bill lam wrote:
Show 11 quoted lines
> On Wed, 21 Jan 2009, Boaz Harrosh wrote:
>> I created a master project folder under ~home, init a new git repo,
>> then symlink /etc/ onto an etc/ in the project dir, added all etc/
>> files. I like the extra a/etc/fstab in the patch files better then
>> a/fstab.
> 
> I create a symlink in ~/gitrepo/etc to /etc and git init an empty repo
> there. However it failed in symlink when I tried to add files.  Could
> you give more detail how to do it?  Meanwhile I use worktree method as
> suggested by Michael.
> 
What? I don't know this is what I did:
[~] $ mkdir gitrepo; cd gitrepo
[gitrepo] $ git-init
[gitrepo] $ ln -s /etc
[gitrepo] $ git-add /etc/fstab
[gitrepo] $ git-commit -s
  Edit commit message in editor
[gitrepo] $ git-show
commit fd6a4a72bf91526b56528f4036c525f6d6fd3dc0
Author: Boaz Harrosh <bharrosh@panasas.com>
Date:   Wed Jan 21 18:36:58 2009 +0200
    {REMOVEME} etc/fstab test
    Signed-off-by: Boaz Harrosh <bharrosh@panasas.com>
diff --git a/etc/fstab b/etc/fstab
new file mode 100644
index 0000000..2e3f8d3
--- /dev/null
+++ b/etc/fstab
@@ -0,0 +1,18 @@
+LABEL=/fc7              /                       ext3    noatime         1 1
+LABEL=/usr0             /usr0                   ext3    noatime         1 2
+LABEL=/boot             /boot                   ext2    noatime         1 2
+LABEL=/fc10             /alt                    ext3    defaults        1 2
+tmpfs                   /dev/shm                tmpfs   defaults        0 0
+devpts                  /dev/pts                devpts  gid=5,mode=620  0 0
+sysfs                   /sys                    sysfs   defaults        0 0
+proc                    /proc                   proc    defaults        0 0
+LABEL=SWAP-sda7         swap                    swap    defaults        0 0
+panstor:/main          /mnt/panstor            nfs     soft,intr,rsize=65536,wsize=65536 0 0
  <... snip ...>

So in short I did nothing. I have git 1.6.0.1

Boaz
bill lam· Jan 22, 2009, 10:00 UTC · re: Boaz Harrosh · lore

Re: how to git a read only directory

On Wed, 21 Jan 2009, Boaz Harrosh wrote:
> [~] $ mkdir gitrepo; cd gitrepo
> [gitrepo] $ git-init
> [gitrepo] $ ln -s /etc
> [gitrepo] $ git-add /etc/fstab

(I use git ver. 1.6.1, git-xxx is already deprecated) I followed your example, and failed in the git add,

gitrepo$ git add /etc/fstab fatal: '/etc/fstab' is outside repository

-- 
regards,
====================================================
GPG key 1024D/4434BAB3 2008-08-24
gpg --keyserver subkeys.pgp.net --recv-keys 4434BAB3
唐詩260 李益  江南曲
    嫁得瞿塘賈  朝朝誤妾期  早知潮有信  嫁與弄潮兒
Boaz Harrosh· Jan 22, 2009, 10:19 UTC · re: bill lam · lore

Re: how to git a read only directory

bill lam wrote:
Show 6 quoted lines
> On Wed, 21 Jan 2009, Boaz Harrosh wrote:
>> [~] $ mkdir gitrepo; cd gitrepo
>> [gitrepo] $ git-init
>> [gitrepo] $ ln -s /etc
>> [gitrepo] $ git-add /etc/fstab
> 

Sorry My mistake, it should be: [gitrepo] $ git-add etc/fstab

Show 6 quoted lines
> (I use git ver. 1.6.1, git-xxx is already deprecated)
> I followed your example, and failed in the git add,
> 
> gitrepo$  git add /etc/fstab
> fatal: '/etc/fstab' is outside repository
> 

Sorry it's a typo, sure you must add files relative to the base directory (one containing the .git/ dir)

Cheers Boaz

bill lam· Jan 22, 2009, 10:29 UTC · re: Boaz Harrosh · lore

Re: how to git a read only directory

On Thu, 22 Jan 2009, Boaz Harrosh wrote:
Show 5 quoted lines
> Sorry My mistake, it should be:
> [gitrepo] $ git-add etc/fstab
> 
> Sorry it's a typo, sure you must add files relative to
> the base directory (one containing the .git/ dir)
Hi Boaz,
I still could not add the file. This time it said symbolic link error.

gitrepo$ ll -A total 4 lrwxrwxrwx 1 bill bill 4 2009-01-22 17:54 etc -> /etc drwxr-xr-x 7 bill bill 4096 2009-01-22 18:23 .git gitrepo$ pwd /home/bill/gitrepo gitrepo$ git add etc/fstab fatal: 'etc/fstab' is beyond a symbolic link

-- 
regards,
====================================================
GPG key 1024D/4434BAB3 2008-08-24
gpg --keyserver subkeys.pgp.net --recv-keys 4434BAB3
唐詩314 王昌齡  長信怨
    奉帚平明金殿開  且將團扇共徘徊  玉顏不及寒鴉色  猶帶昭陽日影來
Boaz Harrosh· Jan 22, 2009, 12:35 UTC · re: bill lam · lore

Re: how to git a read only directory

bill lam wrote:
Show 11 quoted lines
> On Thu, 22 Jan 2009, Boaz Harrosh wrote:
>> Sorry My mistake, it should be:
>> [gitrepo] $ git-add etc/fstab
>>
>> Sorry it's a typo, sure you must add files relative to
>> the base directory (one containing the .git/ dir)
> 
> Hi Boaz,
> 
> I still could not add the file. This time it said symbolic link error.
> 

OK so it looks like it is something new. Good to know I will not upgrade for now as I do use it a lot. Unless there is some config nub that can be turned. I must say that it is most useful, I use it everyday.

Someone please comment why are symlink not allowed. Is that because it might be dangerous? but so is a gun I might shoot myself in the leg, but they are still been sold.

Boaz

← back to recent threads