{"thread":{"id":"584","subject":"Adapting scripts to work in current (not top) directory","startedAt":"2005-05-12T13:58:10Z","lastAt":"2005-05-13T13:53:59Z","messageCount":5,"participants":["Alexey Nezhdanov","H. Peter Anvin","Petr Baudis"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"3151","messageId":"200505121758.10971.snake@penza-gsm.ru","threadId":"584","inReplyTo":null,"subject":"Adapting scripts to work in current (not top) directory","fromName":"Alexey Nezhdanov","fromEmail":"snake@penza-gsm.ru","sentAt":"2005-05-12T13:58:10Z","receivedAt":"2005-05-12T13:58:10Z","isPatch":false,"sender":{"key":"snake@penza-gsm.ru","avatar":null},"body":"All git and cogito scripts wants .git subdirectory. If I'm in a subdirectory \nthat have no .git direcory in it I'm out of luck.\nI have wrote an example script that determines the lowest possible .git \ndirectory position and changes to it to satisfy user request.\n\nProblems with script:\n1) May be I misunderstood the git ideology and it needs not this at all.\n\nif point (1) is false then there are couple of other problems:\n2) Script is extremelly ugly. I'm a week bash programmer so please criticize.\n3) This logic shold be somehow embedded to all git- and cg- scripts. I can not \nfigure how to do it non-intruisively.\n4) files and patch with spaces not supported. Probably fixable but first I \nwant to resolve points (1), (2) and (3)\n\n===========================\n#!/bin/bash\n#\n# Add new file to a GIT repository.\n# Copyright (c) Petr Baudis, 2005\n#\n# Takes a list of file names at the command line, and schedules them\n# for addition to the GIT repository at the next commit.\n\n. ${COGITO_LIB:-/home/snake/lib/cogito/}cg-Xlib\n\n[ \"$1\" ] || die \"usage: cg-add FILE...\"\n\ngitpath=\nsubpath=\ncurpath=`pwd`\nfor ((i=2;i<9999;i=i+1)) ; do {\n        path1=`echo $curpath | cut -d / -f 0-$i`\n        path2=`echo $curpath | cut -d / -f $((i+1))-`\n        [ -d \"$path1\"/.git ] && gitpath=$path1 && subpath=$path2\n        [ \"$path1\" == \"$curpath\" ] && break\n}; done\n\nfor file in \"$@\"; do\n        if [ -f \"$file\" ]; then\n                echo \"Adding file $file\"\n        else\n                die \"$file does not exist\"\n        fi\ndone\n\ncd \"$gitpath\"\n\nfiles=\n\nfor file in \"$@\"; do\n        files=\"$files $subpath/$file\"\ndone\n\ngit-update-cache --add -- $files\n===========================\n\n-- \nRespectfully\nAlexey Nezhdanov\n\n"},{"id":"3177","messageId":"4283AB68.1090003@zytor.com","threadId":"584","inReplyTo":"200505121758.10971.snake@penza-gsm.ru","subject":"Re: Adapting scripts to work in current (not top) directory","fromName":"H. Peter Anvin","fromEmail":"hpa@zytor.com","sentAt":"2005-05-12T19:15:52Z","receivedAt":"2005-05-12T19:15:52Z","isPatch":false,"sender":{"key":"hpa@zytor.com","avatar":null},"body":"Alexey Nezhdanov wrote:\n> All git and cogito scripts wants .git subdirectory. If I'm in a subdirectory \n> that have no .git direcory in it I'm out of luck.\n> I have wrote an example script that determines the lowest possible .git \n> directory position and changes to it to satisfy user request.\n> \n> Problems with script:\n> 1) May be I misunderstood the git ideology and it needs not this at all.\n> \n\nLinus has explicitly said he doesn't want that.\n\n\t-hpa\n"},{"id":"3188","messageId":"20050512201215.GI324@pasky.ji.cz","threadId":"584","inReplyTo":"200505121758.10971.snake@penza-gsm.ru","subject":"Re: Adapting scripts to work in current (not top) directory","fromName":"Petr Baudis","fromEmail":"pasky@ucw.cz","sentAt":"2005-05-12T20:12:15Z","receivedAt":"2005-05-12T20:12:15Z","isPatch":false,"sender":{"key":"pasky@ucw.cz","avatar":"https://avatars.githubusercontent.com/u/18439?v=4"},"body":"Dear diary, on Thu, May 12, 2005 at 03:58:10PM CEST, I got a letter\nwhere Alexey Nezhdanov <snake@penza-gsm.ru> told me that...\n> All git and cogito scripts wants .git subdirectory. If I'm in a subdirectory \n> that have no .git direcory in it I'm out of luck.\n\nThis is fine for Cogito, but Git itself shouldn't care - unless you mean\nthe bundled mini-plumbing scripts. I don't know if anyone (and who) uses\nthem except Linus, but I'm not likely to make much effort to maintain\nthem, or even to actually accept any non-trivial changes to them.\n\n> I have wrote an example script that determines the lowest possible .git \n> directory position and changes to it to satisfy user request.\n> \n> Problems with script:\n> 1) May be I misunderstood the git ideology and it needs not this at all.\n\nCogito really needs it.\n\n> if point (1) is false then there are couple of other problems:\n> 2) Script is extremelly ugly. I'm a week bash programmer so please criticize.\n> 3) This logic shold be somehow embedded to all git- and cg- scripts. I can not \n> figure how to do it non-intruisively.\n\nAdd it to cg-Xlib. You can just update $_git appropriately. (Except when\nyou were explicitly passed GIT_DIR.)\n\n> gitpath=\n> subpath=\n> curpath=`pwd`\n> for ((i=2;i<9999;i=i+1)) ; do {\n>         path1=`echo $curpath | cut -d / -f 0-$i`\n>         path2=`echo $curpath | cut -d / -f $((i+1))-`\n>         [ -d \"$path1\"/.git ] && gitpath=$path1 && subpath=$path2\n>         [ \"$path1\" == \"$curpath\" ] && break\n> }; done\n\nI would gradually trim the $curpath by $(dirname) until I hit\n$curpath/.git or the root directory.\n\n-- \n\t\t\t\tPetr \"Pasky\" Baudis\nStuff: http://pasky.or.cz/\nC++: an octopus made by nailing extra legs onto a dog. -- Steve Taylor\n"},{"id":"3240","messageId":"200505131459.08891.snake@penza-gsm.ru","threadId":"584","inReplyTo":"20050512201215.GI324@pasky.ji.cz","subject":"Re: Adapting scripts to work in current (not top) directory","fromName":"Alexey Nezhdanov","fromEmail":"snake@penza-gsm.ru","sentAt":"2005-05-13T10:59:08Z","receivedAt":"2005-05-13T10:59:08Z","isPatch":false,"sender":{"key":"snake@penza-gsm.ru","avatar":null},"body":"On Friday, 13 May 2005 00:12 Petr Baudis wrote:\n> Dear diary, on Thu, May 12, 2005 at 03:58:10PM CEST, I got a letter\n> where Alexey Nezhdanov <snake@penza-gsm.ru> told me that...\n>\n> > All git and cogito scripts wants .git subdirectory. If I'm in a\n> > subdirectory that have no .git direcory in it I'm out of luck.\n>\n> This is fine for Cogito, but Git itself shouldn't care - unless you mean\n> the bundled mini-plumbing scripts. I don't know if anyone (and who) uses\n> them except Linus, but I'm not likely to make much effort to maintain\n> them, or even to actually accept any non-trivial changes to them.\n>\n> > I have wrote an example script that determines the lowest possible .git\n> > directory position and changes to it to satisfy user request.\n> >\n> > Problems with script:\n> > 1) May be I misunderstood the git ideology and it needs not this at all.\n>\n> Cogito really needs it.\nOk, so sticking with cogito.\n\n> > if point (1) is false then there are couple of other problems:\n> > 2) Script is extremelly ugly. I'm a week bash programmer so please\n> > criticize.\n> > 3) This logic shold be somehow embedded to all git- and cg- \n> > scripts. I can not figure how to do it non-intruisively.\n>\n> Add it to cg-Xlib. You can just update $_git appropriately. (Except when\n> you were explicitly passed GIT_DIR.)\nok, that's easy.\n>\n> > gitpath=\n> > subpath=\n> > curpath=`pwd`\n> > for ((i=2;i<9999;i=i+1)) ; do {\n> >         path1=`echo $curpath | cut -d / -f 0-$i`\n> >         path2=`echo $curpath | cut -d / -f $((i+1))-`\n> >         [ -d \"$path1\"/.git ] && gitpath=$path1 && subpath=$path2\n> >         [ \"$path1\" == \"$curpath\" ] && break\n> > }; done\n>\n> I would gradually trim the $curpath by $(dirname) until I hit\n> $curpath/.git or the root directory.\nI have opted for current directory and not root. Explanation is later this \nmail. New variant:\n=========================\n--- /home/snake/scm/cogito/cg-Xlib      2005-05-12 08:47:29.000000000 +0400\n+++ cg-Xlib     2005-05-13 13:40:58.000000000 +0400\n@@ -8,7 +8,17 @@\n \n _cg_cmd=${0##*/}\n \n-_git=${GIT_DIR:-.git}\n+repopath=`pwd`\n+while ((1)) ; do {\n+  [ -d \"$repopath/.git\" ] && break\n+  [ \"$repopath\" == \"/\" ] && {\n+    repopath=`pwd`;\n+    break;\n+  };\n+  repopath=`dirname $repopath`\n+}; done\n+\n+_git=${GIT_DIR:-$repopath/.git}\n _git_objects=${GIT_OBJECT_DIRECTORY:-$_git/objects}\n=========================\nHere is a problem:\nBecause of git backend only some of the commands should be enabled to work \nfrom current directory. F.e. cg-init should not scan upper directories for \n\".git\" but should instead stick to current directory. In the script above \nthis workarounded as choosing current directory instead of root but this will \nbroke if we trying to initialise repo in a subdirectory of another repo.\nSo I have analysed list of cogito commands to find out which ones should be \nadopted to use \"find repo\" behaivoir:\n\n\"+\" means \"definitely yes\"\n\"-\" means \"definitely no\"\n\"?\" means \"not sure\"\n\".\" means \"not matter\"\n\n+ cg-add\n? cg-admin-lsobj\n- cg-admin-uncommit\n? cg-branch-add\n? cg-branch-ls\n- cg-cancel\n- cg-clone\n- cg-commit\n+ cg-diff\n- cg-export\n. cg-help\n- cg-init\n+ cg-log\n+ cg-ls\n- cg-merge\n+ cg-mkpatch\n? cg-patch\n- cg-pull\n- cg-restore\n+ cg-rm\n- cg-seek\n+ cg-status\n- cg-tag\n? cg-tag-ls\n- cg-update\n. cg-version\n\nAny opinions?\n\n-- \nRespectfully\nAlexey Nezhdanov\n\n"},{"id":"3247","messageId":"20050513135359.GA28138@pasky.ji.cz","threadId":"584","inReplyTo":"200505131459.08891.snake@penza-gsm.ru","subject":"Re: Adapting scripts to work in current (not top) directory","fromName":"Petr Baudis","fromEmail":"pasky@ucw.cz","sentAt":"2005-05-13T13:53:59Z","receivedAt":"2005-05-13T13:53:59Z","isPatch":false,"sender":{"key":"pasky@ucw.cz","avatar":"https://avatars.githubusercontent.com/u/18439?v=4"},"body":"Dear diary, on Fri, May 13, 2005 at 12:59:08PM CEST, I got a letter\n> I have opted for current directory and not root. Explanation is later this \n> mail. New variant:\n\nYes, that's fine.\n\n> =========================\n> --- /home/snake/scm/cogito/cg-Xlib      2005-05-12 08:47:29.000000000 +0400\n> +++ cg-Xlib     2005-05-13 13:40:58.000000000 +0400\n> @@ -8,7 +8,17 @@\n>  \n>  _cg_cmd=${0##*/}\n>  \n> -_git=${GIT_DIR:-.git}\n> +repopath=`pwd`\n> +while ((1)) ; do {\n> +  [ -d \"$repopath/.git\" ] && break\n> +  [ \"$repopath\" == \"/\" ] && {\n> +    repopath=`pwd`;\n> +    break;\n> +  };\n> +  repopath=`dirname $repopath`\n> +}; done\n> +\n> +_git=${GIT_DIR:-$repopath/.git}\n>  _git_objects=${GIT_OBJECT_DIRECTORY:-$_git/objects}\n\nLooks basically fine.\n\n> =========================\n> Here is a problem:\n> Because of git backend only some of the commands should be enabled to work \n> from current directory. F.e. cg-init should not scan upper directories for \n> \".git\" but should instead stick to current directory. In the script above \n> this workarounded as choosing current directory instead of root but this will \n> broke if we trying to initialise repo in a subdirectory of another repo.\n\nI'd set some flag like $reposubdir if .git was found in some of the\nparent directories. Then test that in the relevant commands.\n\n> So I have analysed list of cogito commands to find out which ones should be \n> adopted to use \"find repo\" behaivoir:\n> \n> \"+\" means \"definitely yes\"\n> \"-\" means \"definitely no\"\n> \"?\" means \"not sure\"\n> \".\" means \"not matter\"\n> \n> + cg-add\n> ? cg-admin-lsobj\n\nSure.\n\n> - cg-admin-uncommit\n> ? cg-branch-add\n> ? cg-branch-ls\n\nSure (both).\n\n> - cg-cancel\n> - cg-clone\n> - cg-commit\n\nThis one should, committing only the subdirectory content.\n\n> + cg-diff\n> - cg-export\n\nPerhaps it could export just the subdirectory?\n\n> . cg-help\n> - cg-init\n> + cg-log\n> + cg-ls\n\n(Listing the appropriate subdir.)\n\n> - cg-merge\n> + cg-mkpatch\n> ? cg-patch\n\nThis one should, using the appropriate -p level.\n\n> - cg-pull\n> - cg-restore\n\nThis one should, restoring only the subdirectory.\n\n> + cg-rm\n> - cg-seek\n> + cg-status\n> - cg-tag\n> ? cg-tag-ls\n\nWhy not...\n\n> - cg-update\n> . cg-version\n\n-- \n\t\t\t\tPetr \"Pasky\" Baudis\nStuff: http://pasky.or.cz/\nC++: an octopus made by nailing extra legs onto a dog. -- Steve Taylor\n"}]}