Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Let's say I have around 10 hg repositories cloned in a parent directory (let's call it "parent"). Is there any way I can invoke a mercurial command like hg status on all of the sub-directories rather than performing the laborious act of cding into each directory and then invoking hg status?

I did try out the good old xargs but for some reason it fails to work. The commands which I used are:

find . -maxdepth 1 -type d -print | xargs -t "hg status"

and

ls | xargs -t "hg status"

Update: the solution was to use explicit nameholders when using xargs. Something like:

ls | xargs -t -I {} hg status {}
share|improve this question
    
Remove the quotes. –  Mikel Feb 20 '11 at 6:45
    
@Mikel: Still doesn't work, not that I didn't try it out... :) –  sasuke Feb 20 '11 at 7:17
add comment

2 Answers

up vote 2 down vote accepted
for dir in ./*/
do
  (cd $dir && hg status)
done
share|improve this answer
    
Won't it be possible with a one-liner using the xargs combination? If not, I'd appreciate if you could explain why my one liner doesn't work. Thanks. –  sasuke Feb 20 '11 at 14:51
2  
The xargs version doesn't work because it ends up giving the directories as multiple arguments to a single hg command; this answer issues multiple hg commands in different directories (oh, and use semicolons instead of newlines and that is a one-liner!) –  Norman Gray Feb 20 '11 at 20:40
    
@Norman: Thanks for the clarification. But the question again is, why does ls | xargs grep "something" works but ls | xargs hg status doesn't? –  sasuke Feb 21 '11 at 5:41
1  
@sasuke: grep accepts multiple files as arguments while hg status does not. –  Patches Feb 21 '11 at 6:16
    
But then what about ls | xargs -t -I {} mv {} {}.old? Anyways, I've found the solution and it is to explicitly use placeholders in xargs. Thanks for guiding me on the right way, I'll accept your answer since it also does what I was after. :) –  sasuke Feb 21 '11 at 17:28
add comment

If hg allows running in parallel, you can use GNU Parallel

parallel cd {} '&&' hg status ::: ./*/

If not you can add -j1:

parallel -j1 cd {} '&&' hg status ::: ./*/

Watch the intro video to learn more: http://www.youtube.com/watch?v=OpaiGYxkSuQ

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.