mirror of
https://github.com/nix-community/nixvim.git
synced 2025-06-21 00:25:42 +02:00
flake/generate-files: add --commit
command + fixes
- Added `--commit` with a git-based message - `nix fmt` only operates on files known to git - ensure `generated` directory exists
This commit is contained in:
parent
a5e9dbdef1
commit
7e3d629bb0
1 changed files with 48 additions and 0 deletions
|
@ -9,6 +9,21 @@
|
|||
repo_root=$(git rev-parse --show-toplevel)
|
||||
generated_dir=$repo_root/generated
|
||||
|
||||
commit=
|
||||
while [ $# -gt 0 ]; do
|
||||
case "$1" in
|
||||
--commit) commit=1
|
||||
;;
|
||||
--*) echo "unknown option $1"
|
||||
;;
|
||||
*) echo "unexpected argument $1"
|
||||
;;
|
||||
esac
|
||||
shift
|
||||
done
|
||||
|
||||
mkdir -p "$generated_dir"
|
||||
|
||||
echo "Rust-Analyzer"
|
||||
nix build .#rust-analyzer-options
|
||||
cat ./result >"$generated_dir"/rust-analyzer.nix
|
||||
|
@ -21,7 +36,40 @@
|
|||
nix build .#none-ls-builtins
|
||||
cat ./result >"$generated_dir"/none-ls.nix
|
||||
|
||||
git add --intent-to-add "$generated_dir"
|
||||
nix fmt
|
||||
|
||||
if [ -n "$commit" ]; then
|
||||
cd "$generated_dir"
|
||||
git add .
|
||||
|
||||
# Construct a msg body from `git status`
|
||||
body=$(
|
||||
git status \
|
||||
--short \
|
||||
--ignored=no \
|
||||
--untracked-files=no \
|
||||
--no-ahead-behind \
|
||||
| sed \
|
||||
-e 's/^\s*\([A-Z]\)\s*/\1 /' \
|
||||
-e 's/^A/Added/' \
|
||||
-e 's/^M/Updated/' \
|
||||
-e 's/^R/Renamed/' \
|
||||
-e 's/^D/Removed/' \
|
||||
-e 's/^/- /'
|
||||
)
|
||||
|
||||
# Construct the commit message based on the body
|
||||
count=$(echo "$body" | wc -l)
|
||||
if [ "$count" -gt 1 ] || [ ''${#body} -gt 50 ]; then
|
||||
msg=$(echo -e "generated: Update\n\n$body")
|
||||
else
|
||||
msg="generated:''${body:1}"
|
||||
fi
|
||||
|
||||
# Commit if there are changes
|
||||
[ "$count" -gt 0 ] && git commit -m "$msg" --no-verify
|
||||
fi
|
||||
'';
|
||||
};
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue