Skip to content

Commit

Permalink
hardware config: fix git add logic
Browse files Browse the repository at this point in the history
Fixing the git add hardware config logic in case the user provides a
relative path. We're doing two things:

1. Failing loudly if we're in a git repo and the git add command
   fails. At that point, we already know git is in $PATH. If the git add
   fails, the evaluation will likely fail in a flake setting. Better fail
   early with a helpful git error message.
2. We're resolving the hardware config path in the CLI parsing layer
   to make sure this path has the meaning the user intented it to have.
  • Loading branch information
picnoir authored and picnoir committed Nov 15, 2024
1 parent 51d347d commit e42d66b
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/nixos-anywhere.sh
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ parseArgs() {
abort "Unknown hardware config backend: $2"
;;
esac
hardwareConfigPath=$3
hardwareConfigPath="$(realpath "$3")"
shift
shift
;;
Expand Down Expand Up @@ -456,7 +456,9 @@ generateHardwareConfig() {
# to make sure nix knows about the new file
if command -v git >/dev/null; then
pushd "$(dirname "$hardwareConfigPath")"
git add --intent-to-add --force -- "$hardwareConfigPath" >/dev/null 2>&1 || true
if git rev-parse --is-inside-work-tree >/dev/null; then
git add --intent-to-add --force -- "$hardwareConfigPath"
fi
popd
fi
}
Expand Down

0 comments on commit e42d66b

Please sign in to comment.