]> granicus.if.org Git - nethack/commitdiff
Only update dat/gitinfo.txt if the hash is new
authornhmall <nhmall@nethack.org>
Fri, 26 Jan 2018 13:01:03 +0000 (08:01 -0500)
committernhmall <nhmall@nethack.org>
Fri, 26 Jan 2018 13:01:03 +0000 (08:01 -0500)
DEVEL/hooksdir/NHgithook.pm

index 6024c1c03eb4e8373b5b2fc931e1b78a3910aafd..1bb92cf7ef3d89158bea6d4e300bf4ed7a771988 100644 (file)
@@ -60,6 +60,36 @@ sub POST {
        &do_hook("POST");
 }
 
+###
+### store githash and gitbranch in dat/gitinfo.txt
+###
+
+sub nhversioning {
+    use strict;
+    use warnings;
+
+    my $git_sha = `git rev-parse HEAD`;
+    $git_sha =~ s/\s+//g;
+    my $git_branch = `git rev-parse --abbrev-ref HEAD`;
+    $git_branch =~ s/\s+//g;
+
+    if (open my $fh, '<', 'dat/gitinfo.txt') {
+        while(my $line = <$fh>) {
+            if ((index $line, $git_sha) >= 0) {
+                close $fh;
+                print "No update made to dat/gitinfo.txt, existing githash=".$git_sha."\n";
+                return;
+            }
+        }
+        close $fh;
+    }
+    if (open my $fh, '>', 'dat/gitinfo.txt') {
+        print $fh 'githash='.$git_sha."\n";
+        print $fh 'gitbranch='.$git_branch."\n";
+        print "An updated dat/gitinfo.txt was written, githash=".$git_sha."\n";
+    }
+}
+
 # PRIVATE
 sub do_hook {
        my($p) = @_;