Branch: Tag:

2010-09-27

2010-09-27 21:07:24 by Marcus Comstedt <marcus@mc.pp.se>

Added a post commit hook, to re-checkout files with ident.

6:   mapping(string:program) hooks = ([    "pre-commit" : PreCommitHook,    "pre-receive" : PreReceiveHook, +  "post-commit" : PostCommitHook,   ]);      mapping(string:program) filters = ([
443:    }   }    + /* Do housekeeping after a commit */ +  + class PostCommitHook + { +  void cleanup(string filename, mapping(string:string|int) attr) +  { +  if(attr->ident && attr->ident != GitAttributes.ATTR_FALSE && +  attr->ident != GitAttributes.ATTR_UNSET && +  search(get_committed_file("HEAD", filename, 1), unexpanded_id)>=0) +  if(sizeof(run_git("diff", "--name-only", "--", filename))) { +  write("NOTICE: The file %s has a stale ident,\n but I won't touch it since you have unstaged changes.\n", filename); +  } else { +  // write("Checking out %s, to fix stale ident...\n", filename); +  run_git("checkout", "HEAD", "--", filename); +  } +  } +  +  int hook() +  { +  array(string) committed_files = +  split_z(run_git("diff", "--name-only", "-z", "HEAD", "HEAD^")); +  GitAttributes attrs = +  GitAttributes(get_committed_file("HEAD", ".gitattributes", 1)); +  foreach(committed_files, string filename) +  cleanup(filename, attrs->checkattr(filename)); +  return 0; +  } + } +    /* Filters */      /* A sample filter, not really useful... */