import assert from "assert" ; import { execSync } from "child_process" ; import { CommitExplorer } from "./commit-explorer" ; import process from "process" ; import path from "path" ; const rimraf = require ( "rimraf" ) ; process . chdir ( "./test" ) ; afterEach ( ( ) => { rimraf . sync ( path . resolve ( __dirname , "../test/.git" ) ) ; } ) ; const copyGitFiles = ( name ) => { execSync ( `cp -r ${ path . resolve ( "fixtures" , name ) } ${ path . resolve ( "./" , ".git" ) }` ) ; } ; test ( "detached head" , ( ) => { copyGitFiles ( "detached-head" ) ; expect ( ( ) => new CommitExplorer ( ) . getCurrentBranchName ( ) ) . toThrowError ( ) ; } ) ; test ( "initial commit" , ( ) => { copyGitFiles ( "initial-commit" ) ; const baseHash = new CommitExplorer ( ) . getBaseCommitHash ( ) ; assert . equal ( null , baseHash ) ; } ) ; test ( "master two commits" , ( ) => { copyGitFiles ( "master-two-commits" ) ; const baseHash = new CommitExplorer ( ) . getBaseCommitHash ( ) ; assert . equal ( null , baseHash ) ; } ) ; test ( "after create new branch" , ( ) => { copyGitFiles ( "after-create-new-branch" ) ; const baseHash = new CommitExplorer ( ) . getBaseCommitHash ( ) ; assert . equal ( null , baseHash ) ; } ) ; test ( "commit after create new branch" , ( ) => { copyGitFiles ( "commit-new-branch" ) ; const baseHash = new CommitExplorer ( ) . getBaseCommitHash ( ) ; const expected = execSync ( "git rev-parse expected" , { encoding : "utf8" } ) . trim ( ) ; assert . equal ( expected , baseHash ) ; } ) ; test ( "two commits after create new branch" , ( ) => { copyGitFiles ( "two-commit-new-branch" ) ; const baseHash = new CommitExplorer ( ) . getBaseCommitHash ( ) ; const expected = execSync ( "git rev-parse expected" , { encoding : "utf8" } ) . trim ( ) ; assert . equal ( expected , baseHash ) ; } ) ; test ( "after catch up master merge" , ( ) => { copyGitFiles ( "after-catch-up-master" ) ; const baseHash = new CommitExplorer ( ) . getBaseCommitHash ( ) ; const expected = execSync ( "git rev-parse expected" , { encoding : "utf8" } ) . trim ( ) ; assert . equal ( expected , baseHash ) ; } ) ; test ( "commit after merge" , ( ) => { copyGitFiles ( "commit-after-merge" ) ; const baseHash = new CommitExplorer ( ) . getBaseCommitHash ( ) ; const expected = execSync ( "git rev-parse expected" , { encoding : "utf8" } ) . trim ( ) ; assert . equal ( expected , baseHash ) ; } ) ; test ( "master to catch up branch" , ( ) => { copyGitFiles ( "master-to-catch-up-branch" ) ; const baseHash = new CommitExplorer ( ) . getBaseCommitHash ( ) ; const expected = execSync ( "git rev-parse expected" , { encoding : "utf8" } ) . trim ( ) ; assert . equal ( expected , baseHash ) ; } ) ; test ( "commit after catch up and merge" , ( ) => { copyGitFiles ( "commit-after-catch-up-and-merge" ) ; const baseHash = new CommitExplorer ( ) . getBaseCommitHash ( ) ; const expected = execSync ( "git rev-parse expected" , { encoding : "utf8" } ) . trim ( ) ; assert . equal ( expected , baseHash ) ; } ) ; test ( "after merge catch up" , ( ) => { copyGitFiles ( "after-merge-catch-up" ) ; const baseHash = new CommitExplorer ( ) . getBaseCommitHash ( ) ; const expected = execSync ( "git rev-parse expected" , { encoding : "utf8" } ) . trim ( ) ; assert . equal ( expected , baseHash ) ; } ) ; test ( "merge catch up and commit" , ( ) => { copyGitFiles ( "merge-catch-up-then-commit" ) ; const baseHash = new CommitExplorer ( ) . getBaseCommitHash ( ) ; const expected = execSync ( "git rev-parse expected" , { encoding : "utf8" } ) . trim ( ) ; assert . equal ( expected , baseHash ) ; } ) ; test ( "merge multipe commit three" , ( ) => { copyGitFiles ( "merge-multipe-commit-three" ) ; const baseHash = new CommitExplorer ( ) . getBaseCommitHash ( ) ; const expected = execSync ( "git rev-parse expected" , { encoding : "utf8" } ) . trim ( ) ; assert . equal ( expected , baseHash ) ; } ) ; test ( "error patter found in reg-suit repository" , ( ) => { copyGitFiles ( "reg-suit-error-pattern" ) ; const baseHash = new CommitExplorer ( ) . getBaseCommitHash ( ) ; const expected = "49d38a929ae3675a1c79216709c35884f0b78900" ; assert . equal ( expected , baseHash ) ; } ) ;