github.com/purpleclay/gitz@v0.8.2-0.20240515052600-43f80eea2fe1/docs/git/checks.md (about)

     1  ---
     2  icon: material/clipboard-check-outline
     3  title: Git checks and how to use them
     4  description: A series of inbuilt check for inspecting the environment and current repository
     5  ---
     6  
     7  # Git checks and how to use them
     8  
     9  `gitz` comes with a series of inbuilt checks for inspecting the environment and current repository.
    10  
    11  ## Checking for the existence of a Git Client
    12  
    13  When creating a new client, `gitz` will check for the existence of git using the `PATH` environment variable. An error is returned if no client exists.
    14  
    15  ```{ .go .select linenums="1" }
    16  package main
    17  
    18  import (
    19      "fmt"
    20      "log"
    21  
    22      git "github.com/purpleclay/gitz"
    23  )
    24  
    25  func main() {
    26      client, err := git.NewClient()
    27      if err != nil {
    28          log.Fatal(err.Error())
    29      }
    30  
    31      fmt.Println(client.Version())
    32  }
    33  ```
    34  
    35  ## Checking the integrity of a Repository
    36  
    37  Check the integrity of a repository by running a series of tests and capturing the results for inspection.
    38  
    39  ```{ .go .select linenums="1" }
    40  package main
    41  
    42  import (
    43      "fmt"
    44      "log"
    45  
    46      git "github.com/purpleclay/gitz"
    47  )
    48  
    49  func main() {
    50      client, _ := git.NewClient()
    51  
    52      repo, err := client.Repository()
    53      if err != nil {
    54          log.Fatal("failed to check the current repository")
    55      }
    56  
    57      fmt.Printf("Default Branch: %s\n", repo.DefaultBranch)
    58      fmt.Printf("Detached Head:  %t\n", repo.DetachedHead)
    59      fmt.Printf("Origin:         %s\n", repo.Origin)
    60      fmt.Printf("Remotes:        %#v\n", repo.Remotes)
    61      fmt.Printf("Root Directory: %s\n", repo.RootDir)
    62      fmt.Printf("Shallow Clone:  %t\n", repo.ShallowClone)
    63  }
    64  ```
    65  
    66  Example output when checking the integrity of a repository cloned within a CI system:
    67  
    68  ```{ .text .no-select .no-copy }
    69  Default Branch: main
    70  Detached Head:  true
    71  Origin:         git@github.com:purpleclay/gitz.git
    72  Remotes:        map[string]string{"origin":"git@github.com:purpleclay/gitz.git"}
    73  Root Directory: /dev/github.com/purpleclay/gitz
    74  Shallow Clone:  false
    75  ```