Perform action in dir if dir has .git subdir


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Perform action in dir if dir has .git subdir
# 1  
Old 05-24-2010
MySQL 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 Smilie
# 2  
Old 05-24-2010
Quote:
I want to run git status for the dir which has subdir ".git" in it with dir path mentioned in output log?
Can you please elaborate more?
Please give an example.
# 3  
Old 05-24-2010
MySQL

hi,

project dir will be something like this:
Code:
/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.
Code:
/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 Smilie

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

Smilie

Last edited by Yogesh Sawant; 05-24-2010 at 04:27 AM.. Reason: added code tags
# 4  
Old 05-25-2010
I have no idea of git. but if you want checks about .git dir,
you can do something like:
Code:
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

Code:
/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

# 5  
Old 05-25-2010
MySQL

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.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. AIX

Assign read write permission to the user for specific dir and it's sub dir and files in AIX

I have searched this quite a long time but couldn't find the right method for me to use. I need to assign read write permission to the user for specific directories and it's sub directories and files. I do not want to use ACL. I do not want to assign user the same group of that directories too.... (0 Replies)
Discussion started by: blinkingdan
0 Replies

2. UNIX for Dummies Questions & Answers

How do I create a tar file for only dir and its subdir structures??

How do I create a tar file for only dir and its subdir structures?? (4 Replies)
Discussion started by: vx04
4 Replies

3. UNIX for Dummies Questions & Answers

copying the dir/subdir structure from one server to another?

Hi All, I want to copy the dir/subdir structure from SERVER-A to SERVER-B without copying all the files in each dir. Is it possible using SCP / SFTP command? For example, SERVER-A has following two dir/subdirectories and files under each subdir. ... (1 Reply)
Discussion started by: Hangman2
1 Replies

4. Shell Programming and Scripting

Move all files from dir and subdir to Archive with File name as complete path_filename

HI, I need to move all files from a dir & its all subdir to Archive folder which is indise dir only. and moved filename should changed to complete path ( Like Dir_subdir_subdir2_.._filename ). also all files names shoud capture in a file in order to mail I written below code ... (11 Replies)
Discussion started by: minijain7
11 Replies

5. Shell Programming and Scripting

KSH - Find paths of multiple files in CC (dir and sub-dir))

Dear Members, I have a list of xml files like abc.xml.table prq.xml.table ... .. . in a txt file. Now I have to search the file(s) in all directories and sub-directories and print the full path of file in a output txt file. Please help me with the script or command to do so. ... (11 Replies)
Discussion started by: Yoodit
11 Replies

6. Shell Programming and Scripting

create dir in main &subdirs,perform action

Hi, I have one dir which has N subdirs.For ex: /home/user/Project_Src /home/user/Project_Src/Dir_A /home/user/Project_Src/Dir_A/subdir/sub_dir2 /home/user/Project_Src/Dir_A/subdir/sub_dir3 /home/user/Project_Src/Dir_B /home/user/Project_Src/Dir_B/Build i want to create a folder with... (2 Replies)
Discussion started by: dragon.1431
2 Replies

7. Shell Programming and Scripting

A script to find dir, delete files in, and then del dir?

Hello!! I have directories from 2008, with files in them. I want to create a script that will find the directoried from 2008 (example directory: drwxr-xr-x 2 isplan users 1024 Nov 21 2008 FILES_112108), delete the files within those directories and then delete the directories... (3 Replies)
Discussion started by: bigben1220
3 Replies

8. Shell Programming and Scripting

replace string in multiple files, dir and subdir

Hello, I have a directory www with multiple directories. Every directory has site name with .htm, .html, .php files or sub directories with .htm, .php, .html file as example - www - sitename 1 - site 1 - sitename 2 - sitename 3 What I'm looking for is a... (7 Replies)
Discussion started by: andyjill
7 Replies

9. Shell Programming and Scripting

moving dir subdir and files

I have created a directory structure and under the directory subdirectories and files are there.I need to move the entire thing to another path.How can i write a script to do that. currently the path of files is as below : /data1/serial/mcycle/archive : under this path differnt sub dir exist ... (6 Replies)
Discussion started by: dr46014
6 Replies

10. Shell Programming and Scripting

a script to clone a dir tree, & overwrite the dir struct elsewhere?

hi all, i'm looking for a bash or tcsh script that will clone an empty dir tree 'over' another tree ... specifically, i'd like to: (1) specify a src directory (2) list the directory tree/hiearchy beneath that src dir, w/o files -- just the dirs (3) clone that same, empty dir hierarchy to... (2 Replies)
Discussion started by: OpenMacNews
2 Replies
Login or Register to Ask a Question