threads / patch / 758

patchAllow file list for cg-add through stdin

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

## tl;dr

4 messages between May 29, 2005 and May 29, 2005. Diffs are folded; open one to read it.

replies: 3people: 2as markdown or json

Jochen Roemling· May 29, 2005, 17:40 UTC · lore
|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>
Show changes to cg-add +19 −7
--- 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· May 29, 2005, 18:04 UTC · re: Jochen Roemling · lore

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

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,
Show 6 quoted lines
> 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· May 29, 2005, 18:46 UTC · lore

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

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

Show 16 quoted lines
> 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· May 29, 2005, 20:22 UTC · re: Petr Baudis · lore

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

Petr Baudis wrote:
Show 5 quoted lines
>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>
Show changes to cg-add +7 −8
--- 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

← back to recent threads