Re: Adapting scripts to work in current (not top) directory
- From
- Alexey Nezhdanov <snake@penza-gsm.ru>
- Date
- May 13, 2005, 10:59 UTC
- Message-ID
- <200505131459.08891.snake@penza-gsm.ru>
- In-Reply-To
- <20050512201215.GI324@pasky.ji.cz>
On Friday, 13 May 2005 00:12 Petr Baudis wrote:
Show 18 quoted lines
> Dear diary, on Thu, May 12, 2005 at 03:58:10PM CEST, I got a letter > where Alexey Nezhdanov <snake@penza-gsm.ru> told me that... > > > All git and cogito scripts wants .git subdirectory. If I'm in a > > subdirectory that have no .git direcory in it I'm out of luck. > > This is fine for Cogito, but Git itself shouldn't care - unless you mean > the bundled mini-plumbing scripts. I don't know if anyone (and who) uses > them except Linus, but I'm not likely to make much effort to maintain > them, or even to actually accept any non-trivial changes to them. > > > I have wrote an example script that determines the lowest possible .git > > directory position and changes to it to satisfy user request. > > > > Problems with script: > > 1) May be I misunderstood the git ideology and it needs not this at all. > > Cogito really needs it.
Ok, so sticking with cogito.
Show 8 quoted lines
> > if point (1) is false then there are couple of other problems: > > 2) Script is extremelly ugly. I'm a week bash programmer so please > > criticize. > > 3) This logic shold be somehow embedded to all git- and cg- > > scripts. I can not figure how to do it non-intruisively. > > Add it to cg-Xlib. You can just update $_git appropriately. (Except when > you were explicitly passed GIT_DIR.)
ok, that's easy.
Show 13 quoted lines
>
> > gitpath=
> > subpath=
> > curpath=`pwd`
> > for ((i=2;i<9999;i=i+1)) ; do {
> > path1=`echo $curpath | cut -d / -f 0-$i`
> > path2=`echo $curpath | cut -d / -f $((i+1))-`
> > [ -d "$path1"/.git ] && gitpath=$path1 && subpath=$path2
> > [ "$path1" == "$curpath" ] && break
> > }; done
>
> I would gradually trim the $curpath by $(dirname) until I hit
> $curpath/.git or the root directory.I have opted for current directory and not root. Explanation is later this mail. New variant: ========================= --- /home/snake/scm/cogito/cg-Xlib 2005-05-12 08:47:29.000000000 +0400 +++ cg-Xlib 2005-05-13 13:40:58.000000000 +0400
@@ -8,7 +8,17 @@ _cg_cmd=${0##*/} -_git=${GIT_DIR:-.git} +repopath=`pwd` +while ((1)) ; do { + [ -d "$repopath/.git" ] && break + [ "$repopath" == "/" ] && { + repopath=`pwd`; + break; + }; + repopath=`dirname $repopath` +}; done + +_git=${GIT_DIR:-$repopath/.git} _git_objects=${GIT_OBJECT_DIRECTORY:-$_git/objects} ========================= Here is a problem: Because of git backend only some of the commands should be enabled to work from current directory. F.e. cg-init should not scan upper directories for ".git" but should instead stick to current directory. In the script above this workarounded as choosing current directory instead of root but this will broke if we trying to initialise repo in a subdirectory of another repo. So I have analysed list of cogito commands to find out which ones should be adopted to use "find repo" behaivoir: "+" means "definitely yes" "-" means "definitely no" "?" means "not sure" "." means "not matter" + cg-add ? cg-admin-lsobj - cg-admin-uncommit ? cg-branch-add ? cg-branch-ls - cg-cancel - cg-clone - cg-commit + cg-diff - cg-export . cg-help - cg-init + cg-log + cg-ls - cg-merge + cg-mkpatch ? cg-patch - cg-pull - cg-restore + cg-rm - cg-seek + cg-status - cg-tag ? cg-tag-ls - cg-update . cg-version Any opinions?
-- Respectfully Alexey Nezhdanov