Perform action in dir if dir has .git subdir

Hi,

I want to run git status for the dir which has subdir ".git" in it with dir path mentioned in output log?

If a dir does not have .git subdir then skip that dir.

Dir will have 100 main dirs & 500 + subdirs and so on.

I appreciate all your help :b:

Can you please elaborate more?
Please give an example.

hi,

project dir will be something like this:

/home/user/Source
/home/user/Source/Main_A
/home/user/Source/Main_A/.git
/home/user/Source/Main_A/Test/.git
/home/user/Source/Main_B/.git
/home/user/Source/Main_B/Test
/home/user/Source/Main_B/Test/xyz
/home/user/Source/Main_B/Test/xyz/abc
/home/user/Source/Main_B/Test/xyz/abc/.git

Below mentioned two folders do not have .git subdir so those two should be skipped.

/home/user/Source/Main_B/Test
/home/user/Source/Main_B/Test/xyz

My output log will be like this:
---------
/home/user/Source
On branch master
# Changed but not updated:
# (use "git add/rm <file>..." to update what will be committed)
# (use "git checkout -- <file>..." to discard changes in working directory)

till

/home/user/Source/Main_B/
On branch master
# Changed but not updated:
# (use "git add/rm <file>..." to update what will be committed)
# (use "git checkout -- <file>..." to discard changes in working directory)

/home/user/Source/Main_B/Test/xyz/abc/
On branch bug_fix
# Changed but not updated:
# (use "git add/rm <file>..." to update what will be committed)
# (use "git checkout -- <file>..." to discard changes in working directory)
---------
Please note that /home/user/Source/Main_B/Test/xyz/abc/ has ".git" subdir.
ie /home/user/Source/Main_B/ is parent git, /home/user/Source/Main_B/Test/xyz/abc/ is child1 git.

---------- Post updated at 03:42 AM ---------- Previous update was at 02:23 AM ----------

hi again,

right now im using repo command for the same
repo forall -c "git status" > status.log

In log file i DO NOT get the folder path in which git the files are modified/added/deleted.Hmm, i can get folder path of added/modified files with find/locate command.

For deleted files how do i get the folder path.

Any thoughts :b:

---------- Post updated at 08:17 AM ---------- Previous update was at 03:42 AM ----------

:confused:

I have no idea of git. but if you want checks about .git dir,
you can do something like:

while read path
do
  if [ -d "$path/.git" ];then
    echo ".git exists. git status can be performed"
  else
    echo "git doesnt exists, $path has been skipped"
  fi
done < dir_file

dir_file has the directories path you mentioned above.
i.e

/home/user/Source
/home/user/Source/Main_A
/home/user/Source/Main_A/.git
/home/user/Source/Main_A/Test/.git
/home/user/Source/Main_B/.git
/home/user/Source/Main_B/Test
/home/user/Source/Main_B/Test/xyz
/home/user/Source/Main_B/Test/xyz/abc
/home/user/Source/Main_B/Test/xyz/abc/.git

hi anchal_khare,
Thanks for your response.

as i said earlier ,
If i run repo forall -c "git status"
it does the needed action in my case. however i was not getting dir in which git status ran.

i solved it adding pwd before git status.

I can use your script if i know the dir path. How ever if i have 1000s of 1000 dirs,subdirs first i have to list the dirs n so on.