From 73f17a6bdc2fc75fd568bc3ca222f0af1f96c1e1 Mon Sep 17 00:00:00 2001 From: Kenichi Kamiya Date: Sat, 17 Jun 2023 03:26:07 +0900 Subject: [PATCH] Do not touch if no change occured --- nix-headbump.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/nix-headbump.go b/nix-headbump.go index 3982c7f..e6927e7 100644 --- a/nix-headbump.go +++ b/nix-headbump.go @@ -1,6 +1,7 @@ package main import ( + "bytes" "encoding/json" "flag" "fmt" @@ -52,7 +53,7 @@ type Response struct { } func bump(path string) error { - bytes, err := os.ReadFile(path) + origin, err := os.ReadFile(path) if err != nil { return err } @@ -74,6 +75,10 @@ func bump(path string) error { if json.Unmarshal(body, jsonRes) != nil { return err } - replaced := re.ReplaceAll(bytes, []byte("${1}"+jsonRes.Commit.Sha+"${2}")) + replaced := re.ReplaceAll(origin, []byte("${1}"+jsonRes.Commit.Sha+"${2}")) + if bytes.Equal(origin, replaced) { + return nil + } + return os.WriteFile(path, replaced, os.ModePerm) }