feat: supported branching for commit checking
This commit is contained in:
parent
0c88746da1
commit
260e37e016
3 changed files with 100 additions and 9 deletions
54
rebuild.sh
54
rebuild.sh
|
|
@ -1,5 +1,15 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
# Get current branch and git status for branch-aware behavior
|
||||
current_branch=$(git branch --show-current 2>/dev/null || echo "unknown")
|
||||
git_status=$(git status --porcelain 2>/dev/null || echo "")
|
||||
|
||||
# Default values
|
||||
default_target=$(hostname)
|
||||
default_user="$USER"
|
||||
default_host=$(hostname)
|
||||
default_mode=$(if [[ "$current_branch" != "main" ]]; then echo "test"; else echo "switch"; fi)
|
||||
|
||||
if [ -d "result" ];
|
||||
then
|
||||
preserve_result=true
|
||||
|
|
@ -42,14 +52,29 @@ while [ $# -gt 0 ]; do
|
|||
;;
|
||||
--help|-h)
|
||||
echo "--help -h: print this message"
|
||||
echo "--target -t: set the target system to rebuild on"
|
||||
echo "--flake -f: set the flake to rebuild on the target system"
|
||||
echo "--mode -m: set the mode to rebuild flake as on the target system"
|
||||
echo "--user -u: set the user to rebuild flake as on the target system"
|
||||
echo "--host: set the host that the flake will be rebuilt on (unset for current machine)"
|
||||
echo "--target -t: defaults to the current system"
|
||||
echo " currently: $default_target"
|
||||
echo "--flake -f: defaults to same as target"
|
||||
echo " currently: ${target:-$default_target}"
|
||||
echo "--mode -m: defaults to 'switch', but 'test' on non-main branches"
|
||||
echo " currently would be: $default_mode"
|
||||
echo "--user -u: defaults to the current user"
|
||||
echo " currently: $default_user"
|
||||
echo "--host: defaults to building on the current machine"
|
||||
echo " currently: $default_host"
|
||||
echo "--preserve-result: do not remove the generated result folder after building"
|
||||
echo "--no-preserve-result: remove any result folder after building"
|
||||
echo "--show-trace: show trace on builds"
|
||||
echo ""
|
||||
echo "Branch-aware behavior:"
|
||||
echo " - On non-main branches: defaults to test mode with warning"
|
||||
echo " - On main with uncommitted changes: shows warning about creating a branch"
|
||||
echo " - Current branch: $current_branch"
|
||||
if [[ -n "$git_status" ]]; then
|
||||
echo " - Git status: uncommitted changes detected"
|
||||
else
|
||||
echo " - Git status: clean working tree"
|
||||
fi
|
||||
exit 0
|
||||
;;
|
||||
*)
|
||||
|
|
@ -60,10 +85,21 @@ while [ $# -gt 0 ]; do
|
|||
shift
|
||||
done
|
||||
|
||||
target=${target:-$(hostname)}
|
||||
target=${target:-$default_target}
|
||||
flake=${flake:-$target}
|
||||
mode=${mode:-switch}
|
||||
user=${user:-$USER}
|
||||
mode=${mode:-$default_mode}
|
||||
user=${user:-$default_user}
|
||||
|
||||
# Branch-aware warnings and behavior
|
||||
if [[ "$current_branch" != "main" ]] && [[ "$mode" == "test" ]]; then
|
||||
echo "⚠️ WARNING: You are on branch '$current_branch' (not main)"
|
||||
echo " Defaulting to test mode to prevent accidental system changes"
|
||||
echo " Specify --mode=switch explicitly if you want to apply changes"
|
||||
elif [[ "$current_branch" == "main" ]] && [[ -n "$git_status" ]] && [[ "$mode" != "test" ]]; then
|
||||
echo "⚠️ WARNING: You are on main branch with uncommitted changes"
|
||||
echo " Consider creating a feature branch for development:"
|
||||
echo " git checkout -b feature/your-feature-name"
|
||||
fi
|
||||
|
||||
command="nixos-rebuild $mode --sudo --ask-sudo-password --flake .#$flake"
|
||||
|
||||
|
|
@ -91,4 +127,4 @@ then
|
|||
then
|
||||
rm -r result
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue