Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am working at a client who has a project where code is a mixture of different source control systems. So a layout might be like this


So I am trying to put together a simple command that when executed from the project folder will run the appropriate hg/svn command in each project i.e:

pushd a/
svn up
pushd b/
hg pull

Since the client has many such projects, I would appreciate not having to hardcode the folder structure in a script. Instead I am looking for a solution similar to find -exec where the svn/hg commands are automatically executed on each first level of match (i.e. svn up is run in the project/a folder but not in project/a/subfolder). How can such a command be constructed ?.

share|improve this question
up vote 2 down vote accepted

One idea:

find /project -maxdepth 1 -type d \( -name .svn -execdir svn up \; \
    -o -name .hg -execdir hg pull \; \) 

Edit: perhaps something like

find /project \( -execdir test -d {}/.svn \; -execdir sh -c \
    'cd {} && svn update' \; -o -execdir test -d {}/.hg \; \
    -execdir sh -c 'cd {} && hg pull' \; \) -prune
share|improve this answer
Great although "maxdepth" seams to work on the search level rather than on the result level (i.e. in the above example /c/subproject/ also contains a subversion repo which then has depth 3 from the root). What I want to do is to execute a svn/hg command on the first folder I encounter that is a repo, this folder may be arbitrary nested down). – Lars Tackmann Aug 8 '11 at 15:07
Try the edited version and see if that works. – jw013 Aug 10 '11 at 1:33
Thanks, this works as it should (the commands are now executed in all the correct directories). The only issue left is that it finds the same directory multiple times (executing svn/hg updates is a rather time consuming operation). I wonder if its somehow possible to throw in a unique option. – Lars Tackmann Aug 10 '11 at 7:55
Hmm, hopefully 3rd time's the charm. – jw013 Aug 10 '11 at 9:56
thats it ;) - thanks a allot, I must get more into the power of "find" – Lars Tackmann Aug 10 '11 at 10:33

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .