0.1.0 project setup

This commit is contained in:
SowinskiBraeden committed 2026-09-14 13:45:20 -07:00
1 parent 15706a97f6
commit a09bc5f08c
14 files changed
+153 -337

No files matched your search

+3
View File
@@ -0,0 +1,3 @@
_build/
_opam/
_install/
+7
View File
@@ -0,0 +1,7 @@
Copyright (c) 2026 Braeden Sowinski
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+42 -40
View File
@@ -1,63 +1,65 @@
# git-fleet # git-fleet
Small collection of Git utilities I use to keep my local repositories configured between my self-hosted Gitea instance and GitHub. A Git extension for managing repositories across multiple Git hosts and destinations.
Gitea is my primary Git server. GitHub is kept as a secondary/public copy of my repositories. `git-fleet` is a native CLI I'm building to simplify the Git workflows I use across self-hosted Git services and public hosts. The project started as a few personal scripts for configuring dual-push repositories and is being rebuilt in OCaml as a single, reusable command.
## `setup_dual_push.py` ## Status
Scans my local Git repositories and updates repos owned by `SowinskiBraeden` to use: **v0.1.0: CLI foundation**
- **Fetch:** `git.sowinski.dev` Initial release is just figuring out the project structure and command-line interface:
- **Push:** `git.sowinski.dev`
- **Push:** `github.com`
Other repositories and repositories without a recognized origin are skipped. - Native OCaml executable
- Dune build system
- Cmdliner command interface
- `git fleet` Git subcommand integration
- Automated tests
Useful for configuring existing projects or setting up a new machine. Remote and multi-destination management will begin in v0.2.0.
## `git-new` ## Usage
Small command for initializing new projects with my normal Git configuration. Once `git-fleet` is installed somewhere on your `PATH`, Git automatically exposes it as a subcommand:
Run it from inside the project directory: ```sh
git fleet --help
```bash git fleet --version
git-new <repo-name>
``` ```
It will: You can also invoke the executable directly:
Refuse to run if the directory is already inside a Git repository ```sh
Initialize a new Git repository git-fleet --help
Set the default branch to main
Set Gitea as the fetch origin
Set Gitea and GitHub as push origins
The repo name does not need to match the local directory name.
## Setup
Make the script executable:
```bash
chmod +x git-new
``` ```
Symlink it into /usr/local/bin: ## Development
```bash Install the project dependencies:
sudo ln -s "$(pwd)/git-new" /usr/local/bin/git-new
```sh
opam install . --deps-only --with-test
``` ```
It can then be used from any directory: Build:
```bash ```sh
mkdir my-project dune build
cd my-project
git-new my-repo-name
``` ```
The repositories must already exist on Gitea and GitHub before pushing. Run the tests:
```sh
dune runtest
```
Run the development executable:
```sh
dune exec git-fleet -- --help
dune exec git-fleet -- --version
```
## License
MIT
+5
View File
@@ -0,0 +1,5 @@
(executable
(name main)
(public_name git-fleet)
(package git-fleet)
(libraries git_fleet cmdliner))
+2
View File
@@ -0,0 +1,2 @@
let () =
exit (Cmdliner.Cmd.eval Git_fleet.Cli.cmd)
+27
View File
@@ -0,0 +1,27 @@
(lang dune 3.16)
(name git-fleet)
(version 0.1.0)
(generate_opam_files true)
(source
(github SowinskiBraeden/git-fleet))
(authors "Braeden Sowinski")
(maintainers "Braeden Sowinski <braeden@sowinski.dev>")
(license MIT)
(package
(name git-fleet)
(synopsis "Manage Git repositories across multiple destinations")
(description
"git-fleet is a Git extension for managing repositories across multiple Git hosts and push destinations.")
(depends
(ocaml (>= 5.1))
(dune (>= 3.16))
(cmdliner (>= 1.3.0))
(alcotest :with-test))
(tags
("git" "cli" "developer-tools")))
+34
View File
@@ -0,0 +1,34 @@
# This file is generated by dune, edit dune-project instead
opam-version: "2.0"
version: "0.1.0"
synopsis: "Manage Git repositories across multiple destinations"
description:
"git-fleet is a Git extension for managing repositories across multiple Git hosts and push destinations."
maintainer: ["Braeden Sowinski <braeden@sowinski.dev>"]
authors: ["Braeden Sowinski"]
license: "MIT"
tags: ["git" "cli" "developer-tools"]
homepage: "https://github.com/SowinskiBraeden/git-fleet"
bug-reports: "https://github.com/SowinskiBraeden/git-fleet/issues"
depends: [
"ocaml" {>= "5.1"}
"dune" {>= "3.16" & >= "3.16"}
"cmdliner" {>= "1.3.0"}
"alcotest" {with-test}
"odoc" {with-doc}
]
build: [
["dune" "subst"] {dev}
[
"dune"
"build"
"-p"
name
"-j"
jobs
"@install"
"@runtest" {with-test}
"@doc" {with-doc}
]
]
dev-repo: "git+https://github.com/SowinskiBraeden/git-fleet.git"
-87
View File
@@ -1,87 +0,0 @@
#!/usr/bin/env python3
import subprocess
import sys
from pathlib import Path
OWNER = "SowinskiBraeden"
GITEA_HOST = "git.sowinski.dev"
GITHUB_HOST = "github.com"
def git(*args: str, check: bool = True) -> subprocess.CompletedProcess:
return subprocess.run(
["git", *args],
text=True,
capture_output=True,
check=check,
)
def main():
if len(sys.argv) != 2:
print("Usage: git-new <repo-name>")
sys.exit(1)
repo_name = sys.argv[1].strip()
if not repo_name:
print("Error: repository name cannot be empty.")
sys.exit(1)
current_dir = Path.cwd()
# Refuse to run anywhere inside an existing Git repository.
existing_repo = git("rev-parse", "--show-toplevel", check=False)
if existing_repo.returncode == 0:
repo_root = existing_repo.stdout.strip()
print("Error: already inside a Git repository.")
print(f"Repository root: {repo_root}")
sys.exit(1)
gitea_url = f"git@{GITEA_HOST}:{OWNER}/{repo_name}.git"
github_url = f"git@{GITHUB_HOST}:{OWNER}/{repo_name}.git"
print(f"Initializing: {current_dir}")
print(f"Remote repo: {OWNER}/{repo_name}")
print()
# Initialize repository.
git("init")
# Use main as the initial branch.
git("branch", "-m", "main")
# Gitea is canonical: fetch + first push destination.
git("remote", "add", "origin", gitea_url)
git(
"remote",
"set-url",
"--push",
"origin",
gitea_url,
)
# GitHub is the secondary push destination.
git(
"remote",
"set-url",
"--add",
"--push",
"origin",
github_url,
)
print("Repository initialized.")
print()
print("Remotes:")
print(f" fetch -> {gitea_url}")
print(f" push -> {gitea_url}")
print(f" push -> {github_url}")
if __name__ == "__main__":
main()
+7
View File
@@ -0,0 +1,7 @@
open Cmdliner
let cmd =
let doc = "Manage Git repositories across multiple destinations." in
Cmd.v
(Cmd.info "git-fleet" ~version:Version.value ~doc)
(Term.const ())
+4
View File
@@ -0,0 +1,4 @@
(library
(name git_fleet)
(public_name git-fleet.lib)
(libraries cmdliner))
+1
View File
@@ -0,0 +1 @@
let value = "0.1.0"
-210
View File
@@ -1,210 +0,0 @@
#!/usr/bin/env python3
import re
import subprocess
from pathlib import Path
PROJECTS_DIR = Path.home() / "Projects"
OWNER = "SowinskiBraeden"
GITHUB_HOST = "github.com"
GITEA_HOST = "git.sowinski.dev"
def git(repo: Path, *args: str, check: bool = True) -> subprocess.CompletedProcess:
return subprocess.run(
["git", "-C", str(repo), *args],
text=True,
capture_output=True,
check=check,
)
def find_git_repositories(root: Path) -> list[Path]:
"""Find all Git repositories recursively below root."""
repositories = set()
for git_path in root.rglob(".git"):
if git_path.is_dir() or git_path.is_file():
repositories.add(git_path.parent)
return sorted(repositories)
def parse_repo_name(url: str) -> str | None:
"""
Extract the repository name if the URL belongs to OWNER on either
GitHub or our Gitea instance.
Supported examples:
git@github.com:SowinskiBraeden/example.git
https://github.com/SowinskiBraeden/example.git
git@git.sowinski.dev:SowinskiBraeden/example.git
https://git.sowinski.dev/SowinskiBraeden/example.git
"""
hosts = [
re.escape(GITHUB_HOST),
re.escape(GITEA_HOST),
]
host_pattern = "(?:" + "|".join(hosts) + ")"
patterns = [
rf"^git@{host_pattern}:{re.escape(OWNER)}/([^/]+?)(?:\.git)?$",
rf"^https?://{host_pattern}/{re.escape(OWNER)}/([^/]+?)(?:\.git)?/?$",
rf"^ssh://git@{host_pattern}/{re.escape(OWNER)}/([^/]+?)(?:\.git)?/?$",
]
for pattern in patterns:
match = re.match(pattern, url)
if match:
return match.group(1)
return None
def get_origin(repo: Path) -> str | None:
result = git(
repo,
"remote",
"get-url",
"origin",
check=False,
)
if result.returncode != 0:
return None
return result.stdout.strip()
def configure_repository(repo: Path) -> bool:
origin = get_origin(repo)
if origin is None:
print(f"SKIP {repo}")
print(" No origin remote")
return False
repo_name = parse_repo_name(origin)
if repo_name is None:
print(f"SKIP {repo}")
print(f" Unrecognized/non-{OWNER} origin:")
print(f" {origin}")
return False
gitea_url = f"git@{GITEA_HOST}:{OWNER}/{repo_name}.git"
github_url = f"git@{GITHUB_HOST}:{OWNER}/{repo_name}.git"
print(f"UPDATE {repo}")
print(f" Repository: {OWNER}/{repo_name}")
#
# FETCH
#
# Gitea is authoritative.
#
git(
repo,
"remote",
"set-url",
"origin",
gitea_url,
)
print(f" fetch -> {gitea_url}")
#
# PUSH
#
# Reset the push URL list so running this utility repeatedly cannot
# create duplicate push destinations.
#
current_push_urls = git(
repo,
"remote",
"get-url",
"--all",
"--push",
"origin",
).stdout.splitlines()
# Delete existing explicit push URLs.
#
# Git returns an error if there are no explicit push URLs matching,
# which is harmless here.
for push_url in current_push_urls:
git(
repo,
"remote",
"set-url",
"--delete",
"--push",
"origin",
re.escape(push_url),
check=False,
)
# Establish Gitea as the primary push destination.
git(
repo,
"remote",
"set-url",
"--push",
"origin",
gitea_url,
)
# GitHub remains the public/legacy destination.
git(
repo,
"remote",
"set-url",
"--add",
"--push",
"origin",
github_url,
)
print(f" push -> {gitea_url}")
print(f" push -> {github_url}")
print()
return True
def main():
if not PROJECTS_DIR.exists():
raise SystemExit(
f"Projects directory does not exist: {PROJECTS_DIR}"
)
repositories = find_git_repositories(PROJECTS_DIR)
print(f"Searching: {PROJECTS_DIR}")
print(f"Found {len(repositories)} Git repositories.")
print()
configured = 0
skipped = 0
for repo in repositories:
if configure_repository(repo):
configured += 1
else:
skipped += 1
print("=" * 60)
print("Finished")
print(f"Configured: {configured}")
print(f"Skipped: {skipped}")
print(f"Total: {len(repositories)}")
if __name__ == "__main__":
main()
+3
View File
@@ -0,0 +1,3 @@
(test
(name test_git_fleet)
(libraries git_fleet alcotest))
+18
View File
@@ -0,0 +1,18 @@
let test_version () =
Alcotest.(check string)
"version"
"0.1.0"
Git_fleet.Version.value
let () =
Alcotest.run
"git-fleet"
[
( "version",
[
Alcotest.test_case
"reports 0.1.0"
`Quick
test_version;
] );
]