# [COGITO PATCH] Allow file list for cg-add through stdin

4 messages from 2005-05-29 to 2005-05-29. Participants: Jochen Roemling, Petr Baudis.
Thread: https://gitlist.dev/t/758

## Jochen Roemling, 2005-05-29 17:40

Subject: [COGITO PATCH] Allow file list for cg-add through stdin
Message-ID: <4299FE8A.1060207@roemling.net>
URL: https://gitlist.dev/e/4299FE8A.1060207%40roemling.net

```
|Hello,

how is the preferred way to add a whole new directory to a 
git-repository using cogito?
Currently cg-add expects all new files on the command line.
The following patch allows to feed files through stdin, which allows to do

    find mynewdir -type f | cg-add -

What about a functionality to specify a directory on the command line 
and all files are
recursively added?

Signed-off-by: Jochen Roemling <jochen@roemling.net>

--- a/cg-add      2005-05-29 19:27:17.000000000 +0200
+++ b/cg-add      2005-05-29 19:32:42.000000000 +0200
@@ -10,12 +10,24 @@

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

-for file in "$@"; do
-       if [ -f "$file" ] || [ -h "$file" ]; then
-               echo "Adding file $file"
-       else
-               die "$file does not exist"
-       fi
-done
+if [ "$1" == '-' ]; then
+       set $@ ""
+       while read file; do
+               if [ -f "$file" ] || [ -h "$file" ]; then
+                       echo "Adding file $file"
+                       set $@ "$file"
+               else
+                       die "$file does not exist"
+               fi
+       done
+else
+       for file in "$@"; do
+               if [ -f "$file" ] || [ -h "$file" ]; then
+                       echo "Adding file $file"
+               else
+                       die "$file does not exist"
+               fi
+       done
+fi

 git-update-cache --add -- "$@"

|

```

## Petr Baudis, 2005-05-29 18:04

Subject: Re: [COGITO PATCH] Allow file list for cg-add through stdin
Message-ID: <20050529180442.GK1036@pasky.ji.cz>
URL: https://gitlist.dev/e/20050529180442.GK1036%40pasky.ji.cz
In-Reply-To: <4299FE8A.1060207@roemling.net>

```
Dear diary, on Sun, May 29, 2005 at 07:40:26PM CEST, I got a letter
where Jochen Roemling <jochen@roemling.net> told me that...
> |Hello,

Hello,

> how is the preferred way to add a whole new directory to a 
> git-repository using cogito?
> Currently cg-add expects all new files on the command line.
> The following patch allows to feed files through stdin, which allows to do
> 
>    find mynewdir -type f | cg-add -

if you really want to do that, pass it through xargs...

> What about a functionality to specify a directory on the command line 
> and all files are
> recursively added?

...but I think this is definitively the right way to go.

-- 
				Petr "Pasky" Baudis
Stuff: http://pasky.or.cz/
C++: an octopus made by nailing extra legs onto a dog. -- Steve Taylor

```

## Petr Baudis, 2005-05-29 18:46

Subject: Re: [COGITO PATCH] Allow file list for cg-add through stdin
Message-ID: <20050529184642.GL1036@pasky.ji.cz>
URL: https://gitlist.dev/e/20050529184642.GL1036%40pasky.ji.cz
In-Reply-To: <429A0818.6080807@roemling.net>

```
Dear diary, on Sun, May 29, 2005 at 08:21:12PM CEST, I got a letter
where Jochen Roemling <jochen@roemling.net> told me that...
> Petr Baudis wrote:
> 
> >>how is the preferred way to add a whole new directory to a 
> >>git-repository using cogito?
> >>Currently cg-add expects all new files on the command line.
> >>The following patch allows to feed files through stdin, which allows to do
> >>
> >>  find mynewdir -type f | cg-add -
> >>   
> >>
> >
> >if you really want to do that, pass it through xargs...
> >
> > 
> >
> We have 32° in this room and my xargs must have been melted down.

It's awfully hot here too. :/

> How could I forget about one of my favorite commands?
> I promise I will not post to this list anymore today to avoid a bigger mess.

But a patch for cg-add processing directories recursively would be great
anyway... ;-)

-- 
				Petr "Pasky" Baudis
Stuff: http://pasky.or.cz/
C++: an octopus made by nailing extra legs onto a dog. -- Steve Taylor

```

## Jochen Roemling, 2005-05-29 20:22

Subject: Re: [COGITO PATCH] Allow file list for cg-add through stdin
Message-ID: <429A24A1.1010402@roemling.net>
URL: https://gitlist.dev/e/429A24A1.1010402%40roemling.net
In-Reply-To: <20050529184642.GL1036@pasky.ji.cz>

```
Petr Baudis wrote:

>But a patch for cg-add processing directories recursively would be great
>anyway... ;-)
>
>  
>
Okay, okay, what about this one:


[Cogito PATCH] Add directories recursively  with cg-add

Signed-off-by: Jochen Roemling <jochen@roemling.net>

--- a/cg-add

+++ b/cg-add

@@ -10,12 +10,11 @@

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

-for file in "$@"; do

-	if [ -f "$file" ] || [ -h "$file" ]; then

-		echo "Adding file $file"

-	else

-		die "$file does not exist"

-	fi

-done

+TMPFILE="${TMP:-/tmp}/$(basename $0).$$.tmp"

-git-update-cache --add -- "$@"

+find $@ -type f > $TMPFILE || die "not all files do exist, nothing added"

+

+cat $TMPFILE | awk '{print "Adding file "  $0}' 

+cat $TMPFILE | xargs git-update-cache --add -- 

+

+rm -f $TMPFILE


```
