git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Adapting scripts to work in current (not top) directory
@ 2005-05-12 13:58 Alexey Nezhdanov
  2005-05-12 19:15 ` H. Peter Anvin
  2005-05-12 20:12 ` Petr Baudis
  0 siblings, 2 replies; 5+ messages in thread
From: Alexey Nezhdanov @ 2005-05-12 13:58 UTC (permalink / raw)
  To: GIT Mailing List

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.
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.

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.
4) files and patch with spaces not supported. Probably fixable but first I 
want to resolve points (1), (2) and (3)

===========================
#!/bin/bash
#
# Add new file to a GIT repository.
# Copyright (c) Petr Baudis, 2005
#
# Takes a list of file names at the command line, and schedules them
# for addition to the GIT repository at the next commit.

. ${COGITO_LIB:-/home/snake/lib/cogito/}cg-Xlib

[ "$1" ] || die "usage: cg-add FILE..."

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

for file in "$@"; do
        if [ -f "$file" ]; then
                echo "Adding file $file"
        else
                die "$file does not exist"
        fi
done

cd "$gitpath"

files=

for file in "$@"; do
        files="$files $subpath/$file"
done

git-update-cache --add -- $files
===========================

-- 
Respectfully
Alexey Nezhdanov


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2005-05-13 13:46 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-05-12 13:58 Adapting scripts to work in current (not top) directory Alexey Nezhdanov
2005-05-12 19:15 ` H. Peter Anvin
2005-05-12 20:12 ` Petr Baudis
2005-05-13 10:59   ` Alexey Nezhdanov
2005-05-13 13:53     ` Petr Baudis

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).