Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
This repository was archived by the owner on Oct 17, 2021. It is now read-only.

SwiftDocOrg/GitConfig

Open more actions menu

Repository files navigation

GitConfig

CI

A Swift library for parsing Git configuration files.

Requirements

  • Swift 5.3+

Usage

let example = #"""
# This is an example .git/config file
[core]
    repositoryformatversion = 0
    filemode = true
    bare = false

    # equivalent to "blank-at-eol,blank-at-eof"
    whitespace = trailing-space

# [unused]
#   should-be-parsed = false

[remote "origin"]
    url = git@github.com:SwiftDocOrg/GitConfig.git
    fetch = +refs/heads/*:refs/remotes/origin/*
    gh-resolved = base
"""#

let configuration = try Configuration(example)
configuration.sections.count // 2

// Sections are stored in declaration order
// and can be retrieved by array index or by name
configuration["core"] == configuration.sections[0] // true

configuration["core"]?["repositoryformatversion"] // 0
configuration["core"]?["filemode"] // true
configuration["core"]?["bare"] // "trailing-space"
configuration["core"]?["whitespace"] // false
configuration["core"]?["undefined"] // nil

let remote = configuration["remote \"origin\""]
remote["url"] // "git@github.com:SwiftDocOrg/GitConfig.git"
remote["fetch"] // "+refs/heads/*:refs/remotes/origin/*"
remote["gh-resolved"] // "base"

Installation

Swift Package Manager

Add the GitConfig package to your target dependencies in Package.swift:

import PackageDescription

let package = Package(
  name: "YourProject",
  dependencies: [
    .package(
        url: "https://github.com/SwiftDocOrg/GitConfig",
        from: "0.0.1"
    ),
  ]
)

Add GitConfig as a dependency to your target(s):

targets: [
.target(
    name: "YourTarget",
    dependencies: ["GitConfig"]),

License

MIT

Contact

Mattt (@mattt)

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

Morty Proxy This is a proxified and sanitized view of the page, visit original site.