Query Project git Status
hendrenja opened this issue · 0 comments
hendrenja commented
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"