Skip to contentSkip to conversation

how to git a read only directory

DISCUSSION bill lam 3 participants 10 messages Jun 15, 2016

lore
Share & tools
lore

bill lam

author
#0 lore raw

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.

Signature · 7 lines
regards,
====================================================
GPG key 1024D/4434BAB3 2008-08-24
gpg --keyserver subkeys.pgp.net --recv-keys 4434BAB3
唐詩164 張喬  書邊事
    調角斷清秋  征人倚戍樓  春風對青塚  白日落梁州
    大漠無兵阻  窮邊有客遊  蕃情似此水  長願向南流
#1 lore raw

bill lam venit, vidit, dixit 21.01.2009 09:33:

Quoted 7 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
}
#3 lore raw
In reply to bill lam
Quoted 7 lines · bill lam

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

author
#2 lore raw
In reply to Michael J Gruber
Quoted 4 lines · Michael J Gruber

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.

Signature · 6 lines
regards,
====================================================
GPG key 1024D/4434BAB3 2008-08-24
gpg --keyserver subkeys.pgp.net --recv-keys 4434BAB3
唐詩267 王翰  涼州詞
    葡萄美酒夜光杯  欲飲琵琶馬上催  醉臥沙場君莫笑  古來征戰幾人回
author
#4 lore raw
In reply to Boaz Harrosh
Quoted 4 lines · Boaz Harrosh

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.

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

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 <[email protected]>
Date:   Wed Jan 21 18:36:58 2009 +0200

{REMOVEME} etc/fstab test

etc/fstab new file +10 -0
new file mode 100644
index 0000000..2e3f8d3
@@ -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

author
#6 lore raw
Quoted 4 lines · Boaz Harrosh

[~] $ 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

Signature · 6 lines
regards,
====================================================
GPG key 1024D/4434BAB3 2008-08-24
gpg --keyserver subkeys.pgp.net --recv-keys 4434BAB3
唐詩260 李益  江南曲
    嫁得瞿塘賈  朝朝誤妾期  早知潮有信  嫁與弄潮兒
#7 lore raw
Quoted 6 lines · bill lam
Quoted 4 lines · Boaz Harrosh

[~] $ 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

Quoted 6 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

author
#8 lore raw
Quoted 5 lines · Boaz Harrosh

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

Signature · 6 lines
regards,
====================================================
GPG key 1024D/4434BAB3 2008-08-24
gpg --keyserver subkeys.pgp.net --recv-keys 4434BAB3
唐詩314 王昌齡  長信怨
    奉帚平明金殿開  且將團扇共徘徊  玉顏不及寒鴉色  猶帶昭陽日影來
#9 lore raw
Quoted 11 lines · bill lam
Quoted 5 lines · Boaz Harrosh

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