Introducing list-repos

List Repos

List Repos

What a tedious and confusing task it is to manage multiple repositories! Multiple repositories where few of them were copies of same repos but on different branches.

So I have come up with this utility to solve the least bit of this problem by listing the repos-directories and their active branches to quickly decide on the target directory to work on.

Attempt #1

In the beginning I had created a shell based solution which was very brittle and accepted no input. It changed the directories and echoed the active branch.

#!/bin/bash

echo "Brahch Listing"
cd /c/xampp/htdocs/
cd ./REPO1
x="$(git rev-parse --abbrev-ref HEAD)"
printf "REPO1\t$x"

cd ./REPO2
x="$(git rev-parse --abbrev-ref HEAD)"
printf "REPO2\t$x"

cd ./REPO3
x="$(git rev-parse --abbrev-ref HEAD)"
printf "REPO3\t$x"

cd ./REPO4
x="$(git rev-parse --abbrev-ref HEAD)"
printf "REPO4\t$x"

Attempt #2

Later the script got modified to do shell loops and had one hard-coded value. It was looking good but still brittle as it had one hard-coded value in terms of the directory to look into.

#!/bin/bash

echo "Brahch Listing"
cd /c/xampp/htdocs/

RED='\033[0;31m'
BLUE='\033[1;34m'
GREEN='\033[1;32m'
NC='\033[0m' # No Color

for i in $( ls ); do
    cd $i
    if [ $? -eq 0 ]; then
        # echo $i
        output="$i"
        git rev-parse --abbrev-ref HEAD &> /dev/null
        if [ $? -eq 0 ]; then
            # output="$output $x"
            x="$(git rev-parse --abbrev-ref HEAD)"
            printf "${BLUE}$output\t${GREEN}$x"
        else
            printf "${BLUE}$output\t${RED}--"
        fi
        printf "\n"
        cd ..
    fi
done 

Attempt #3

But later thes whole code got rewritten in JavaScript to provide a quick and easy CLI utility to provide you info of the repositories. You can find the package at https://www.npmjs.com/package/list-repos

To install it on your system, simply type the following command and hit enter:

npm i -g list-repos

And to use it, type following command and hit enter:

list-repos <dir-path>

The `<dir-path>` in above command is the path where all the copies of repositories are. Hence for above hardcoded example, `/c/xampp/htdocs` is the directory where the copies are, command will be

list-repos /c/xampp/htdocs

And on running above command, it will generate output like following:

/c/xampp/htdocs
┌─────────────────────────────┬───────────────────┐
│ Directory                   │ Current Branch/NA │
├─────────────────────────────┼───────────────────┤
│ movieDB                     │ master            │
├─────────────────────────────┼───────────────────┤
│ list-repos                  │ master            │
├─────────────────────────────┼───────────────────┤
│ list-repos-old              │ old               │
├─────────────────────────────┼───────────────────┤
│ get-it-ready                │ master            │
├─────────────────────────────┼───────────────────┤
│ time2hack                   │ master            │
├─────────────────────────────┼───────────────────┤
│ ui-bootstrap                │ master            │
└─────────────────────────────┴───────────────────┘

This utility can accept the relative paths. So suppose I am in any of the above directories, I can launch the utility with `..` to get the list in following way and will generate same output as above:

list-repos ..

Please use the tool and let me know if you think of any new feature or encounter any problem in the comments. The tool is open source and can be forked from https://github.com/pankajpatel/list-repos


Got Something To Say:

Your email address will not be published. Required fields are marked *

*