Skip to content

Query Project git Status #3

@hendrenja

Description

@hendrenja

In growing projects, I am constantly forgetting which project folders have been synced with their remote git branches. I will be writing a bake tool/plugin that queries each project's bake status. The plugin shall support the following

  • Ignore non-git projects
  • Report non-tracked changes
  • Report non-staged changes
  • Report commits behind origin/master (needs fetch)
    Considerations: git fetch origin is required, which requires remote query (SLOW)
  • Specify commits ahead of origin/master (non-pushed)

Bash Example

#!/bin/bash

i=0
for file in */ ; do
    cd ${file}
    if [ -d .git ]; then
        git fetch origin
        if output=$(git status --porcelain) && [ -z "$output" ]; then
            # echo "$file is clean";
            # if output=$(git status -uno) && [ -z "$output" ]; then
            # fi
            ahead=$(git rev-list --right-only --count origin/master...master)
            behind=$(git rev-list --left-only --count origin/master...master)
            if [ ${ahead} -ne "0" ]; then
                echo "$file | Changes AHEAD of origin/master"
                i=$((i+1))
            fi
            if [ ${behind} -ne "0" ]; then
                echo "$file | Changes BEHIND origin/master"
                i=$((i+1))
            fi
            cd ..
        else
            echo "$file | Untracked Files ";
            i=$((i+1))
            cd ..
        fi
    else
        # echo "Skip $file"
        cd ..
    fi
done

echo "[$i] git repos need attention"

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions