U e=!@sddlmZddlZddlZddlZddlmZddlm Z ddl m Z ddl m Z ddl m Z eeZdZd d d d d ZdIdddddZd dddZdJd d dddZdKd d dddZddddZdd d d!d"Zd#dd$d%ZdLd&d d'd(d)Zd dd*d+Zd dd,d-Zd d d d.d/d0Zd d d1d2d3Zdd4d d dd5d6d7Zddd8d9Z d d d:d;dd?d@Z"dNd d d dAdBdCZ#d:ddDdEZ$d d d dFdGdHZ%dS)O) annotationsN)Mapping) FatalError)CalledProcessError) cmd_output cmd_output_b)z-czcore.useBuiltinFSMonitor=falsestrz list[str])sreturncCs |d}|r|dSgSdS)N)stripsplit)r r GIT_SSL_NO_VERIFYGIT_HTTP_PROXY_AUTHMETHODGIT_SSH GIT_EXEC_PATHGIT_SSH_COMMANDGIT_SSL_CAINFOGIT_CONFIG_COUNTGIT_ALLOW_PROTOCOL GIT_ASKPASS) startswith).0kvrrr %s   zno_git_env..)osenvironitems)rrrr no_git_envs r$)r cCsfz4tjtdddd}tdddd}Wntk rPtdYnX|dkrbtd|S) Ngit rev-parsez --show-cdupz--is-inside-git-dirzGgit failed. Is it installed, and are you in a Git repository directory?falsezfgit toplevel unexpectedly empty! make sure you are not inside the `.git` directory of your repository.)r!pathabspathrr rr)rootZinside_git_dirrrrget_root3s(  r,.)git_rootr cCsLd}tdd||d\}}}|}||kr@tjtj||StddS)Nz --git-dirr%r&cwdzunreachable: no git dir)rr r!r)normpathjoinAssertionError)r.opt_outgit_dirrrr get_git_dirLs r8cCsLd}tdd||d\}}}|}||kr@tjtj||St|SdS)Nz--git-common-dirr%r&r/)rr r!r)r1r2r8)r.r4r5r6Zgit_common_dirrrrget_git_common_dirVs r9boolcCs4td}tjtj|do2tjtj|dS)Nr- MERGE_MSG MERGE_HEAD)r8r!r)existsr2)r7rrris_in_merge_conflict`sr>bytes) merge_msgr cCsdd|DS)NcSs(g|] }|dr|dqS)) s# #)rlstripr decode)rlinerrr js z1parse_merge_msg_for_conflicts..) splitlines)r@rrrparse_merge_msg_for_conflictshsrHzset[str]c Cstdttjtddd}|}W5QRXt|}t ddd }t t ddd d d d |d d d}t |t |BS)Nz#Checking merge-conflict files only.r-r;rbr%z write-treer'diff --name-only --no-ext-diff-zz-mHEADr<) loggerinfoopenr!r)r2r8readrHrr rset)fr@Zmerge_conflict_filenamesZ tree_hashZmerge_diff_filenamesrrrget_conflicted_filesrs* rUz str | None)r0r c Cs ttddddddd|dd S) Nr%rJz--stagedrKrLrMz--diff-filter=ACMRTUXBr/r'rrr/rrrget_staged_filessrWcCs"tddddddd\}}}t|S)Nr%rJrLz--ignore-submodulesz--diff-filter=ArKrM)rr)r5stdoutrrrintent_to_add_filess rYcCsttddddS)Nr%zls-filesrMr'rVrrrr get_all_filessrZ)oldnewr cCsbd}z"t||d|f\}}}Wn2tk rXt||d|f\}}}YnXt|S)N)r%rJrKrLrMz...z..)rrr)r[r\Zdiff_cmdr5r6rrrget_changed_filess "$r])remoter cCs"tddd|d\}}}|dS)Nr%z ls-remotez --exit-coderNr)rr)r^r5r6rrrhead_revsr_)repo)argsr`r cGs d |}t||ddddkS) Nr%rJ--quietrLF)r0checkrr')r%rJrbrLr)r`racmdrrrhas_diffsrecCs"tddddd\}}}t|S)Nr%configzcore.hooksPathF)rc)rr:r )r5r6rrrhas_core_hookpaths_setsrgNone)r)r^r cCs^tj|rtj|}d t}t}t|dd|fd|it|ddd|f||ddS) Nr%initz --template=envr^addoriginr0rj)r%)r!r)isdirr* NO_FS_MONITORr$r)r)r^r%rjrrr init_repos   rp)r`r cCsFt}d\}}||d<|d<||d<|d<d}t|||ddS)N)z pre-commitzasottile+pre-commit@umich.eduZGIT_AUTHOR_NAMEZGIT_COMMITTER_NAMEZGIT_AUTHOR_EMAILZGIT_COMMITTER_EMAIL)r%commitz --no-editz --no-gpg-signz-nz-minitrm)r$r)r`rjnameemailrdrrrrqs rq)rrr`r cCs*tddd||d\}}}tj||S)Nr%r&z --git-pathr/)rr!r)r2r )rrr`r5r6rrrgit_pathsrtcCsvtjdkrrtjdk}z t}Wntk r4YdSX|d}||Arrddd}td||d ||d dS) z7See https://github.com/pre-commit/pre-commit/issues/354)cygwinwin32ruN/z(cygwin)z (windows))TFa pre-commit has detected a mix of cygwin python / git This combination is not supported, it is likely you will receive an error later in the program. Make sure to use cygwin git+python while using cygwin These can be installed through the cygwin installer. - python z - git  )sysplatformr,rrrOwarn)Zis_cygwin_pythontoplevelZ is_cygwin_gitZexe_typerrrcheck_for_cygwin_mismatchs     r})revgit_repor cCs@tdtdd|fd|id}|D]}d|kr&|Sq&|S)zGet the best tag candidate. Multiple tags can exist on a SHA. Sometimes a moving tag is attached to a version tag. Try to pick the tag that looks like a version. r%tagz --points-atr0r'r-)r%)rrorG)r~rtagsrrrrget_best_candidate_tags  r)N)r-)r-)N)r-)r-)& __future__rloggingos.pathr!rytypingrZpre_commit.errorsrZpre_commit.utilrrr getLogger__name__rOrorr$r,r8r9r>rHrUrWrYrZr]r_rergrprqrtr}rrrrrs<