1212
1313
1414# This is used to identify the hook file we install
15- PREVIOUS_IDENTIFYING_HASHES = (
15+ PRIOR_HASHES = (
1616 '4d9958c90bc262f47553e2c073f14cfe' ,
1717 'd8ee923c46731b42cd95cc869add4062' ,
1818 '49fd668cb42069aa1b6048464be5d395' ,
1919 '79f09a650522a87b0da915d0d983b2de' ,
2020 'e358c9dae00eac5d06b38dfdb1e33a8c' ,
2121)
22+ CURRENT_HASH = '138fd403232d2ddd5efb44317e38bf03'
2223
2324
24- IDENTIFYING_HASH = '138fd403232d2ddd5efb44317e38bf03'
25-
26-
27- def is_our_pre_commit (filename ):
28- if not os .path .exists (filename ):
29- return False
30- return IDENTIFYING_HASH in io .open (filename ).read ()
31-
32-
33- def is_previous_pre_commit (filename ):
25+ def is_our_script (filename ):
3426 if not os .path .exists (filename ):
3527 return False
3628 contents = io .open (filename ).read ()
37- return any (hash in contents for hash in PREVIOUS_IDENTIFYING_HASHES )
29+ return any (h in contents for h in ( CURRENT_HASH ,) + PRIOR_HASHES )
3830
3931
4032def install (runner , overwrite = False , hooks = False , hook_type = 'pre-commit' ):
@@ -45,11 +37,7 @@ def install(runner, overwrite=False, hooks=False, hook_type='pre-commit'):
4537 mkdirp (os .path .dirname (hook_path ))
4638
4739 # If we have an existing hook, move it to pre-commit.legacy
48- if (
49- os .path .lexists (hook_path ) and
50- not is_our_pre_commit (hook_path ) and
51- not is_previous_pre_commit (hook_path )
52- ):
40+ if os .path .lexists (hook_path ) and not is_our_script (hook_path ):
5341 os .rename (hook_path , legacy_path )
5442
5543 # If we specify overwrite, we simply delete the legacy file
@@ -97,12 +85,7 @@ def uninstall(runner, hook_type='pre-commit'):
9785 hook_path = runner .get_hook_path (hook_type )
9886 legacy_path = hook_path + '.legacy'
9987 # If our file doesn't exist or it isn't ours, gtfo.
100- if (
101- not os .path .exists (hook_path ) or (
102- not is_our_pre_commit (hook_path ) and
103- not is_previous_pre_commit (hook_path )
104- )
105- ):
88+ if not os .path .exists (hook_path ) or not is_our_script (hook_path ):
10689 return 0
10790
10891 os .remove (hook_path )
0 commit comments