Re: [git-users] extracting subdirectory from git repo

2013-09-22 Thread Konstantin Khomoutov
On Fri, 20 Sep 2013 09:54:57 -0700 (PDT)
Gabriel Marchesan Almeida gabrielmarche...@gmail.com wrote:

 Konstantin, me again.
 
 I have realized that when running your commands directly on prompt
 command, they work pretty fine and I have an output on /tmp/valid,
 which is exactly the TAG i want to keep.
 
 However when putting the command in a bash script, I have always
 empty /tmp/valid.
 
 I am having problems to figure out where the problem is coming from.

A couple of points:

First, remove the subshell (...) which is in front of | sort -u ...
as it's not really needed -- a simple pipeline would do just fine:

git rev-list --branches |
while read c; do git tag --contains $c; done |
sort -u /tmp/valid

Next, just verify every part of the pipeline works as intended,
that is:

1) Place a call

   git rev-list --branches

   before the pipeline and see if it prints a set of SHA-1 names.

2) Place a call to `git tag --list` before the pipeline to verify the
   tags are there.

3) Replace `git tag --contains $c` in the `while` body with mere
   `echo $c` and see if that works.

Next, it's almost always advisable to run the script with the fail on
errors and fail on undefined variables flags turned on, which is
done by executing

set -e -u

in the script.  This helps detect subtle errors.

Next, while `set -e -u` is usually a must, this does not prevent faulty
pipelines from failing (a really brain-dead property of the standard
Unix shell).  If (and only if) you're using bash, make it fail on
faulty pipelines by running `set -o pipefail` and hence the recommended
thing to include in the script is

set -e -u -o pipefail

This way bash will die with an error message as soon as any program it
calls anywhere exits with a non-error exit code.

Last, in scripts, never hard-code names of temporary files -- use
mktemp instead:

FNAME=`mktemp git.`
trap 'rm -rf $FNAME' TERM INT EXIT

... sort -u $FNAME
...
... grep -f $FNAME

 
 Small area of my script.
 
 http://screenpresso.com/=zAske

Next time please use a pastebin service [1] like, uh, pastebin.com,
or https://gist.github.com/ and so on -- they're in abundance.
There's no need to use graphics to present text.

1. http://en.wikipedia.org/wiki/Pastebin

-- 
You received this message because you are subscribed to the Google Groups Git 
for human beings group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to git-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Re: [git-users] extracting subdirectory from git repo

2013-09-20 Thread Gabriel Marchesan Almeida
Konstantin, me again.

I have realized that when running your commands directly on prompt command, 
they work pretty fine and I have an output on /tmp/valid, which is exactly 
the TAG i want to keep.

However when putting the command in a bash script, I have always empty 
/tmp/valid.

I am having problems to figure out where the problem is coming from.

Small area of my script.

http://screenpresso.com/=zAske

Thanks in advance for your help!

On Tuesday, September 17, 2013 3:47:27 PM UTC+2, Konstantin Khomoutov wrote:

 On Tue, 17 Sep 2013 05:21:08 -0700 (PDT) 
 Gabriel Marchesan Almeida gabrielm...@gmail.com javascript: wrote: 

  I am trying to extract subdirectories from a git repo and I have done 
  so far these steps.. 
 ---Filter
  

  subdirectory 
  
  git filter-branch --tag-name-filter cat --prune-empty 
  --subdirectory-filter ./Subfolder HEAD 
  
   Delete history 
  
  git reset --hard 
  git for-each-ref --format=%(refname) refs/original/ | xargs -n 1 
  git update-ref -d git reflog expire --expire=now --all 
  git gc --aggressive --prune=now 
  
  
 ---
  

  
  The problem is that it extracts all the tags and not the only ones 
  from this repo. 

 What do you mean by from this repo?  There's no such thing as tags 
 from this repo and tags not from this repo. 

 Or do you mean the resulting repository contains tags pointing to 
 commits which do not belong to the new set of commits `git 
 filter-branch` created when it was synthesizing the new history? 

 Then I'd say the way to go would be along the lines of: 

 $ (git rev-list --branches 
   | while read c; do git tag --contains $c; done) | 
   sort -u /tmp/valid 
 $ git tag --list | grep -v -F -f /tmp/valid | 
   while read t; do git tag -d $t; done 

 That is, on the first step create a list of all tags pointing to 
 commits reachable from your branches then on the second step obtain the 
 list of tags which are not in the set generated on the previous step, 
 and delete them.  I have not tested this solution -- it's just an idea. 


-- 
You received this message because you are subscribed to the Google Groups Git 
for human beings group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to git-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Re: [git-users] extracting subdirectory from git repo

2013-09-18 Thread Gabriel Marchesan Almeida
That's great, thanks a lot Konstantin!

On Tuesday, September 17, 2013 3:47:27 PM UTC+2, Konstantin Khomoutov wrote:

 On Tue, 17 Sep 2013 05:21:08 -0700 (PDT) 
 Gabriel Marchesan Almeida gabrielm...@gmail.com javascript: wrote: 

  I am trying to extract subdirectories from a git repo and I have done 
  so far these steps.. 
 ---Filter
  

  subdirectory 
  
  git filter-branch --tag-name-filter cat --prune-empty 
  --subdirectory-filter ./Subfolder HEAD 
  
   Delete history 
  
  git reset --hard 
  git for-each-ref --format=%(refname) refs/original/ | xargs -n 1 
  git update-ref -d git reflog expire --expire=now --all 
  git gc --aggressive --prune=now 
  
  
 ---
  

  
  The problem is that it extracts all the tags and not the only ones 
  from this repo. 

 What do you mean by from this repo?  There's no such thing as tags 
 from this repo and tags not from this repo. 

 Or do you mean the resulting repository contains tags pointing to 
 commits which do not belong to the new set of commits `git 
 filter-branch` created when it was synthesizing the new history? 

 Then I'd say the way to go would be along the lines of: 

 $ (git rev-list --branches 
   | while read c; do git tag --contains $c; done) | 
   sort -u /tmp/valid 
 $ git tag --list | grep -v -F -f /tmp/valid | 
   while read t; do git tag -d $t; done 

 That is, on the first step create a list of all tags pointing to 
 commits reachable from your branches then on the second step obtain the 
 list of tags which are not in the set generated on the previous step, 
 and delete them.  I have not tested this solution -- it's just an idea. 


-- 
You received this message because you are subscribed to the Google Groups Git 
for human beings group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to git-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.