diff options
author | Adam Spragg <adam@spra.gg> | 2022-05-23 16:23:50 +0100 |
---|---|---|
committer | Adam Spragg <adam@spra.gg> | 2022-05-24 10:12:33 +0100 |
commit | 0ca5825e790fd9ab034dd8ab7511732e1905000c (patch) | |
tree | 590fe58a03fd20a9e6fdd804f5489b42f9c4e1c9 | |
parent | 2e368d6bfdfba4efc651b5cfcd37b075deb79e4d (diff) |
Abort commits during conflicts if differences exist
If the user is running `git commit` to resolve a conflict, it's
dangerous to just save the metadata from the filesystem. It's possible
that they just fixed a conflict in the metadata file, but didn't update
the on-disk metadata to match.
(I know it's possible, because I did this!)
Our normal mode of operation, of just saving the metadata during a
commit to match whatever's on-disk, would wipe out their careful
conflict resolution! (On the other hand, just overwriting the on-disk
metadata might not be the best idea either.)
But the point of a conflict is that the changes between two different
branches *can't* be resolved automatically, and requires manual
intervention. Given that situation, asking them to resolve the
difference manually seems to be the most obvious option.
-rw-r--r-- | examples/hooks/pre-commit | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/examples/hooks/pre-commit b/examples/hooks/pre-commit index dc79432..e4cc8ea 100644 --- a/examples/hooks/pre-commit +++ b/examples/hooks/pre-commit @@ -24,6 +24,18 @@ exit_on_fail() { fi } +if git rev-parse MERGE_HEAD >/dev/null 2>&1 \ + && [ -e "$MSFILE" ] \ + && ! metastore -c -q -f "$MSFILE"; then + echo "In git Conflict resolution, and saved metadata does not match filesystem" + echo "metadata. Unable to fix automatically. Try:" + echo " metastore -cf \"$MSFILE\" -- Shows where the differences are" + echo " metastore -df \"$MSFILE\" -- Shows the stored metadata" + echo " metastore -sf \"$MSFILE\" -- Save current filesystem metadata as-is" + echo " metastore -af \"$MSFILE\" -- Apply saved metadata to filesystem" + exit 1 +fi + exit_on_fail \ metastore -s -f "$MSFILE" |