`git dirs' custom command to get git status for multiple directories recursively

Post your FreeBASIC source, examples, tips and tricks here. Please don’t post code without including an explanation.
Post Reply
coderJeff
Site Admin
Posts: 4326
Joined: Nov 04, 2005 14:23
Location: Ontario, Canada
Contact:

`git dirs' custom command to get git status for multiple directories recursively

Post by coderJeff »

I created a custom command for git that can get the status of multiple local git repositories. There are similar ideas posted around the web using bash scripts, etc. I have created this one as a freebasic executable.

It works for me, for what I am doing, but it needs more testing. I have only used it on Win7.

Code is posted at the following gist:
https://gist.github.com/jayrm/b1fbc8199 ... 076fc090d2

Here is an example of the execution & output:

Code: Select all

E:\fb>git dirs --status --recursive
        fbtools/cleanrc/
        fbtools/dtools/
                [master]: files modified (use "git add")
        fbtools/gettime/
        fbtools/git-dirs/
                [single-module]: files modified (use "git add")
                [single-module]: files staged (use "git commit")
                [single-module]: 1 commit(s) ahead (use "git push")
        fbtools/mkvideo/
        fbtools/scantree/
        fbtools/scantree/libjrm/
        fbtools/tmp/
                [master]: no upstream branch (use "git push --set-upstream origin master")
        fbtools/wakeup/
        libjrm/
                [master]: 6 commit(s) ahead (use "git push")

E:\fb>git dirs -h
usage: git dirs [options]

    -a, --all             all directories (except system)
    --color[=yes|no]      color formatting
    -r, --recursive       recursive
    -s, --sorted          sorted
    --status              query status of each git dir
    --fetch               perform a 'fetch --all --tags' at each git dir
    --system              include system directories
    -v, --verbose         be more verbose

E:\fb>
Basic procedure for the utility is as follows:
1) scan directories, recursively if option given
2) If .git folder found; it's a git repo, if .git file fond, it's a git submodule
3) execute some git shell/pipe commands on the git directory to determine the status
4) print the results

Over the years I have created many little utilities and projects. There are a few that I use regularly and I keep maintained. I have been making efforts to organize my source tree because I find that I have so many duplicate copies of similar files. I am using file:////server/share/path.git strategy on a LAN share for the upstream repo's. As I was creating more and more git repos, I needed this utility to help remind me what the state of each repo was.

Hope it is useful.
counting_pine
Site Admin
Posts: 6323
Joined: Jul 05, 2005 17:32
Location: Manchester, Lancs

Re: `git dirs' custom command to get git status for multiple directories recursively

Post by counting_pine »

Pretty cool. It works well for me on Linux.
With '--status', it does show this message on some repos: fatal: no upstream configured for branch 'master'
Which I imagine is just a slightly less polite way of saying the master branch doesn't have a remote it can be pushed to.
coderJeff
Site Admin
Posts: 4326
Joined: Nov 04, 2005 14:23
Location: Ontario, Canada
Contact:

Re: `git dirs' custom command to get git status for multiple directories recursively

Post by coderJeff »

counting_pine, thank-you for testing and reporting results. Fixed some bugs, added tests for detached head & no upstream branch. Now shows the current branch.

Updates on gist link:

- added: only follow system directories if --system command line option is given (was finding git repos in windows recycle bin)
- fixed: print <current directory> when current directory is a git repo or submodule
- fixed: only perform git fetch and status queries for git directories
- added: test for detached head
- added: test for no upstream branch
- added: --verbose option to show shell/pipe commands
- added: print current branch for each status ouput

(top post updated to show updated sample output)

Thanks again.
Post Reply