### tsrc foreach Command Examples (Bash) Source: https://github.com/tk-aria/wmgr/blob/main/USER_GUIDE.md Provides examples of using 'tsrc foreach' to execute commands across repositories, including pulling, installing dependencies, running tests in parallel, and checking Git status. ```bash # Pull all repositories tsrc foreach "git pull" # Install dependencies in web repositories tsrc foreach "npm install" --group web # Run tests in parallel tsrc foreach "make test" --parallel # Check Git status tsrc foreach "git status --porcelain" ``` -------------------------------- ### Install tsrc from Source (Bash) Source: https://github.com/tk-aria/wmgr/blob/main/USER_GUIDE.md Instructions to clone the tsrc repository, navigate to the v2 directory, and build the release version using Cargo. ```bash git clone https://github.com/tk-aria/wmgr.git cd wmgr/v2 cargo build --release ``` -------------------------------- ### tsrc apply-manifest Command Example (Bash) Source: https://github.com/tk-aria/wmgr/blob/main/USER_GUIDE.md An example of how to apply a new manifest file to the current workspace using the 'tsrc apply-manifest' command. ```bash # Apply updated manifest tsrc apply-manifest updated-manifest.yml ``` -------------------------------- ### tsrc init Command Examples (Bash) Source: https://github.com/tk-aria/wmgr/blob/main/USER_GUIDE.md Demonstrates various ways to use the 'tsrc init' command, including initializing all repositories, specific groups, multiple groups, and forcing re-initialization. ```bash # Initialize all repositories tsrc init manifest.yml # Initialize only web repositories tsrc init manifest.yml --group web # Initialize multiple groups tsrc init manifest.yml --group web --group api # Force re-initialization tsrc init manifest.yml --force ``` -------------------------------- ### Initialize Workspace with tsrc (Bash) Source: https://github.com/tk-aria/wmgr/blob/main/USER_GUIDE.md Steps to create a new workspace directory, initialize it using 'tsrc init' with a manifest file, and verify the setup with 'tsrc status'. ```bash mkdir my-workspace cd my-workspace tsrc init manifest.yml tsrc status ``` -------------------------------- ### Example manifest.yml (YAML) Source: https://github.com/tk-aria/wmgr/blob/main/USER_GUIDE.md A sample manifest file used for initializing a tsrc workspace, defining two repositories with their destinations, URLs, branches, and group assignments. ```yaml repos: - dest: "frontend" url: "https://github.com/myorg/frontend.git" branch: "main" groups: ["web"] - dest: "backend" url: "https://github.com/myorg/backend.git" branch: "main" groups: ["api"] ``` -------------------------------- ### Manual wmgr Installation Source: https://github.com/tk-aria/wmgr/blob/main/README.md These commands demonstrate manual installation of wmgr by downloading pre-compiled binaries for different platforms. It involves downloading a tar.gz archive, extracting it, and moving the wmgr binary to a directory in your system's PATH. ```bash # Linux x86_64 wget https://github.com/tk-aria/wmgr/releases/latest/download/wmgr-linux-x86_64.tar.gz tar xzf wmgr-linux-x86_64.tar.gz sudo mv wmgr /usr/local/bin/ # macOS ARM64 (M1/M2) wget https://github.com/tk-aria/wmgr/releases/latest/download/wmgr-darwin-aarch64.tar.gz tar xzf wmgr-darwin-aarch64.tar.gz sudo mv wmgr /usr/local/bin/ # macOS x86_64 (Intel) wget https://github.com/tk-aria/wmgr/releases/latest/download/wmgr-darwin-x86_64.tar.gz tar xzf wmgr-darwin-x86_64.tar.gz sudo mv wmgr /usr/local/bin/ # Windows x86_64 # Download wmgr-windows-x86_64.tar.gz from releases page # Extract and place wmgr.exe in your PATH ``` -------------------------------- ### Workspace Configuration Example (.wmgr/config.yml) Source: https://github.com/tk-aria/wmgr/blob/main/README.md An example configuration file for wmgr, specifying the manifest path, default groups, and the workspace root directory. ```yaml # Path to the manifest file (relative to workspace root) manifest_path: "manifest.yml" # Default groups to use when none specified groups: ["core", "web"] # Workspace root path workspace_path: "/path/to/workspace" ``` -------------------------------- ### Git Commit Command Example Source: https://github.com/tk-aria/wmgr/blob/main/CLAUDE.md Example of executing Git add and commit commands directly without additional confirmation. This is a standard command-line operation for version control. ```bash git add . git commit -m "..." ``` -------------------------------- ### Install wmgr using Cargo Source: https://github.com/tk-aria/wmgr/blob/main/README.md This command demonstrates installing wmgr directly from its Git repository using the Cargo package manager. This method requires Rust and Cargo to be installed on the system. ```bash cargo install --git https://github.com/tk-aria/wmgr.git wmgr ``` -------------------------------- ### tsrc Help and Version Check Source: https://github.com/tk-aria/wmgr/blob/main/USER_GUIDE.md Commands to access command-line help for tsrc and check its installed version. Essential for understanding available options and verifying installation. ```bash tsrc --help tsrc --help tsrc --version ``` -------------------------------- ### Group Strategy Examples (YAML) Source: https://github.com/tk-aria/wmgr/blob/main/USER_GUIDE.md Provides examples of how to define group strategies in YAML configuration, categorizing repositories by technology, team, feature, or environment. This aids in flexible project management. ```yaml # By Technology: groups: ["react", "node", "python"] # By Team: groups: ["frontend-team", "backend-team", "devops-team"] # By Feature: groups: ["authentication", "payments", "analytics"] # By Environment: groups: ["development", "staging", "production"] ``` -------------------------------- ### tsrc sync Command Examples (Bash) Source: https://github.com/tk-aria/wmgr/blob/main/USER_GUIDE.md Illustrates different uses of the 'tsrc sync' command, such as syncing all repositories, specific groups, forcing sync with uncommitted changes, and syncing without branch correction. ```bash # Sync all repositories tsrc sync # Sync only API repositories tsrc sync --group api # Force sync with uncommitted changes tsrc sync --force # Sync without switching branches tsrc sync --no-correct-branch ``` -------------------------------- ### Install wmgr Script Source: https://github.com/tk-aria/wmgr/blob/main/README.md This snippet shows how to install wmgr using the official install script. It supports installing the latest version, a specific version, or to a custom location. The script handles OS and architecture detection, downloads the binary, and sets permissions. ```bash # Install latest version curl -sSLf https://raw.githubusercontent.com/tk-aria/wmgr/main/scripts/install.sh | sh # Install specific version curl -sSLf https://raw.githubusercontent.com/tk-aria/wmgr/main/scripts/install.sh | WMGR_VERSION=v0.1.14 sh # Install to custom location curl -sSLf https://raw.githubusercontent.com/tk-aria/wmgr/main/scripts/install.sh | WMGR_INSTALL_PATH=/usr/bin sh ``` -------------------------------- ### tsrc log Command Examples (Bash) Source: https://github.com/tk-aria/wmgr/blob/main/USER_GUIDE.md Demonstrates how to use the 'tsrc log' command to view commit logs across repositories, with an example for filtering by group. ```bash # Show recent commits tsrc log # Show commits for specific group tsrc log --group web ``` -------------------------------- ### wmgr Configuration Example Source: https://github.com/tk-aria/wmgr/blob/main/README.md This YAML snippet shows an example of a wmgr configuration file (`.wmgr/config.yml`). It specifies the path to the manifest file, default groups, and the workspace path. ```yaml manifest_path: "manifest.yml" groups: ["web", "api"] workspace_path: "/path/to/workspace" ``` -------------------------------- ### Example Manifest Repository Configuration (YAML) Source: https://github.com/tk-aria/wmgr/blob/main/uithub_tsrc.txt A sample YAML configuration for a manifest repository, defining multiple repositories with their URLs and destinations. ```yaml # In acme.com:your-team/manifest - manifest.yml repos: - url: git@acme.com:your-team/manifest dest: manifest - url: git@acme.com:your-team/foo dest: foo - url: git@acme.com:your-team/bar dest: bar ``` -------------------------------- ### tsrc status Command Examples (Bash) Source: https://github.com/tk-aria/wmgr/blob/main/USER_GUIDE.md Shows how to use the 'tsrc status' command for basic status checks, including options to display branch information and use a compact output format. ```bash # Basic status tsrc status # Status with branch information tsrc status --branch # Compact output tsrc status --compact ``` -------------------------------- ### Install Development Dependencies with Poetry Source: https://github.com/tk-aria/wmgr/blob/main/uithub_tsrc.txt This command installs development and documentation dependencies using Poetry. It ensures all necessary packages for contributing and testing are available. Requires Poetry to be installed. ```console $ poetry install ``` -------------------------------- ### Example Workspace Configuration Source: https://github.com/tk-aria/wmgr/blob/main/uithub_tsrc.txt Represents the configuration of a tsrc workspace, typically generated after running `tsrc init`. It specifies the manifest URL and branch, along with other settings like repository groups and cloning behavior. This file guides `tsrc sync` and other workspace operations. ```yaml manifest_url: git@github.com:dmerejkowsky/dummy-manifest manifest_branch: main repo_groups: [] shallow_clones: false clone_all_repos: false singular_remote: ``` -------------------------------- ### tsrc Command Line Usage Examples Source: https://github.com/tk-aria/wmgr/blob/main/uithub_tsrc.txt Demonstrates basic tsrc command-line syntax, including global options and subcommands. It shows how to apply options like `--verbose` before a command and how to initialize a workspace with a manifest URL. ```console $ tsrc --verbose sync $ tsrc init MANIFEST_URL ``` -------------------------------- ### Manifest Configuration Example Source: https://github.com/tk-aria/wmgr/blob/main/uithub_tsrc.txt An example of a manifest.yml file, demonstrating the structure for defining repositories, their URLs, destinations, branches, remotes, tags, file copying, and symlink creation. This YAML file is used by tsrc to manage project workspaces. ```yaml repos: - url: git@gitlab.local:proj1/foo dest: foo branch: next remotes: - name: origin url: git@gitlab.local:proj1/bar - name: upstream url: git@github.com:user/bar dest: bar branch: master sha1: ad2b68539c78e749a372414165acdf2a1bb68203 - url: git@gitlab.local:proj1/app dest: app tag: v0.1 copy: - file: top.cmake dest: CMakeLists.txt - file: .clangformat symlink: - source: app/some_file target: ../foo/some_file ``` -------------------------------- ### Serve Documentation Locally with Poetry and MkDocs Source: https://github.com/tk-aria/wmgr/blob/main/uithub_tsrc.txt This command launches a local development server for MkDocs to preview documentation changes. It requires MkDocs to be installed as a development dependency. Navigate to the docs directory before running. ```bash $ poetry run mkdocs serve ``` -------------------------------- ### wmgr Example Workflow (Bash) Source: https://github.com/tk-aria/wmgr/blob/main/README.md A typical workflow using the 'wmgr' tool, including initialization, status checks, synchronization, running tests, and updating specific groups of repositories. ```bash # Clone and set up workspace wmgr init manifest.yml # Check what needs to be done wmgr status # Sync everything wmgr sync # Run tests across all repositories wmgr foreach "make test" --parallel # Update only web components wmgr sync --group web # Check status with branch info wmgr status --branch ``` -------------------------------- ### Best Practice: Parallel Execution for Speed (Bash) Source: https://github.com/tk-aria/wmgr/blob/main/USER_GUIDE.md Highlights the best practice of using parallel execution for tsrc commands to improve operational speed. Examples include parallel sync and parallel command execution using `tsrc foreach`. ```bash # Faster operations tsrc sync --parallel tsrc foreach "make test" --parallel ``` -------------------------------- ### Rust: Initialize ConfigStore Source: https://github.com/tk-aria/wmgr/blob/main/docs/wmgr/infrastructure/filesystem/config_store/struct.ConfigStore.html Provides a constructor function `new` for the ConfigStore. This method creates a new instance of ConfigStore with default settings, making it easy to start managing configurations. ```rust pub fn new() -> Self { // Implementation details omitted for brevity unimplemented!("new not implemented yet") } ``` -------------------------------- ### Initialize Workspace with tsrc Source: https://github.com/tk-aria/wmgr/blob/main/docs/EXAMPLES.md Initializes a new Git workspace using tsrc. Requires a manifest URL and a target workspace path. Supports specifying a branch, groups, and shallow cloning. Returns a Result containing the initialized workspace or a TsrcError. ```rust use tsrc::application::use_cases::init_workspace::{ InitWorkspaceUseCase, InitWorkspaceConfig }; use tsrc::domain::value_objects::{git_url::GitUrl, file_path::FilePath}; async fn init_workspace() -> tsrc::Result<()><{ let config = InitWorkspaceConfig { manifest_url: GitUrl::new("https://github.com/example/manifest.git")?, workspace_path: FilePath::new_absolute("/path/to/workspace")?, branch: Some("main".to_string()), groups: None, shallow: false, force: false, }; let use_case = InitWorkspaceUseCase::new(config); let workspace = use_case.execute().await?; println!("Workspace initialized at: {:?}", workspace.root_path); Ok(()) } ``` -------------------------------- ### Tsrc Development Setup (Bash) Source: https://github.com/tk-aria/wmgr/blob/main/README.md These bash commands outline the initial steps for contributing to the tsrc project, including forking the repository, cloning the fork, creating a feature branch, and building the project locally. ```bash 1. Fork the repository 2. Clone your fork: `git clone https://github.com/your-username/wmgr.git` 3. Create a feature branch: `git checkout -b feature/amazing-feature` 4. Install development dependencies: `cargo build` ``` -------------------------------- ### Create and Checkout New Branch (Rust) Source: https://github.com/tk-aria/wmgr/blob/main/docs/src/wmgr/infrastructure/git/repository.rs.html Creates a new Git branch and checks it out. The new branch can be created from a specified starting point (commit, branch, or tag) or from the current HEAD if no starting point is provided. It ensures the branch is created and then checks it out. ```Rust let start_commit = if let Some(start) = start_point { // Find the start point commit let reference = self .repo .find_reference(start) .or_else(|_| self.repo.find_reference(&format!("refs/heads/{}", start))) .or_else(|_| { self.repo .find_reference(&format!("refs/remotes/origin/{}", start)) }) .map_err(|_| GitRepositoryError::BranchNotFound(start.to_string()))?; reference.peel_to_commit()?.* } else { // Use HEAD self.repo.head()?.peel_to_commit()?.* }; // Create the branch let _branch = self .repo .branch(branch_name.as_str(), &start_commit, false)?; // Checkout the new branch self.checkout(branch_name.as_str())?; Ok(()) ``` -------------------------------- ### Example manifest.yml Configuration Source: https://github.com/tk-aria/wmgr/blob/main/uithub_tsrc.txt Defines a list of Git repositories to be managed by tsrc. Each repository entry includes a destination path and its URL. This structure is used to set up a workspace for cloning and synchronization. ```yaml repos: - dest: foo url: git@example.com:foo.git - dest: bar url: git@example.com:bar.git ``` -------------------------------- ### Rust: Examples of Using GitUrl Value Object Source: https://github.com/tk-aria/wmgr/blob/main/docs/EXAMPLES.md This Rust code demonstrates various ways to use the `GitUrl` value object from the `tsrc` crate. It covers creating `GitUrl` instances from HTTPS and SSH formats, extracting repository and organization names, converting between URL formats, and checking if two URLs refer to the same repository. ```rust use tsrc::domain::value_objects::git_url::GitUrl; fn git_url_examples() -> tsrc::Result<()> { // Create URLs let https_url = GitUrl::new("https://github.com/owner/repo.git")?; let ssh_url = GitUrl::new("git@github.com:owner/repo.git")?; // Extract information println!("Repository name: {:?}", https_url.repo_name()); println!("Organization: {:?}", https_url.organization()); // Convert formats println!("SSH URL: {}", https_url.to_ssh_url()); // Check if URLs point to same repository assert!(https_url.is_same_repo(&ssh_url)); Ok(()) } ``` -------------------------------- ### Tsrc Installation and Usage in GitHub Actions (Bash) Source: https://github.com/tk-aria/wmgr/blob/main/README.md This YAML snippet shows a GitHub Actions workflow that installs tsrc from a release URL, initializes a workspace using a manifest file, runs tests across multiple repositories using `wmgr foreach`, and checks the status. ```yaml name: Multi-repo CI on: [push, pull_request] jobs: test: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - name: Install tsrc run: | curl -L https://github.com/tk-aria/wmgr/releases/latest/download/tsrc-linux-x86_64.tar.gz | tar xz sudo mv tsrc /usr/local/bin/ - name: Initialize workspace run: wmgr init manifest.yml - name: Run tests run: wmgr foreach "make test" --parallel - name: Check status run: wmgr status ``` -------------------------------- ### Install tsrc and Sync Repositories in GitHub Actions Source: https://github.com/tk-aria/wmgr/blob/main/uithub_tsrc.txt This snippet demonstrates how to set up a GitHub Actions workflow to install tsrc, configure Git for private repositories using an access token, initialize the tsrc workspace with a manifest, and synchronize all repositories. It's designed for environments needing to clone private GitHub repositories using SSH. ```yaml name: tsrc with private github repos on: workflow_dispatch: branches: - main jobs: export_linux: runs-on: ubuntu-latest steps: - name: Installing tsrc tool run: | sudo apt-get update sudo apt-get install -y python3 python -m pip install tsrc - name: Cloning private github repos run: | git config --global url."https://${{ secrets.ACCESS_TOKEN }}@github.com/".insteadOf git@github.com: export WORKSPACE=$GITHUB_WORKSPACE/your_project mkdir -p $WORKSPACE cd $WORKSPACE tsrc init git@github.com:yourorganisation/manifest.git tsrc sync ``` -------------------------------- ### Initialize and Configure Repository Source: https://github.com/tk-aria/wmgr/blob/main/docs/src/wmgr/domain/entities/repository.rs.html Demonstrates initializing a Repository with a path and remotes, then configuring specific branch, SHA1, and shallow clone settings. It asserts the correctness of these configurations. ```rust let repo = Repository::new("path/to/repo", remotes) .with_branch("main") .with_sha1("abc123") .with_shallow(true); assert_eq!(repo.branch, Some("main".to_string())); assert_eq!(repo.sha1, Some("abc123".to_string())); assert!(repo.shallow); assert!(repo.has_fixed_ref()); ``` -------------------------------- ### Complex Workflow: Multi-stage Deployment (Bash) Source: https://github.com/tk-aria/wmgr/blob/main/USER_GUIDE.md Outlines a multi-stage deployment workflow using tsrc commands. This includes synchronizing repositories, building services in parallel, running tests, and deploying to production environments. ```bash # Stage 1: Update all repositories tsrc sync # Stage 2: Build services tsrc foreach "make build" --group services --parallel # Stage 3: Run tests tsrc foreach "make test" --parallel # Stage 4: Deploy tsrc foreach "make deploy" --group production ``` -------------------------------- ### Git Commit Manifest Changes Source: https://github.com/tk-aria/wmgr/blob/main/USER_GUIDE.md Example of using a meaningful commit message for manifest updates. Helps in understanding the context of changes at a glance. ```bash git commit -m "manifest: add payment service to api group" ``` -------------------------------- ### Initialize and Open Git Repository in Rust Source: https://github.com/tk-aria/wmgr/blob/main/docs/src/wmgr/infrastructure/git/repository.rs.html Demonstrates initializing a new Git repository at a specified path and subsequently opening it. This involves using the `GitRepository::init` and `GitRepository::open` methods. The `init` method creates a new repository, while `open` loads an existing one. Error handling for non-existent repositories is also shown. ```rust /// Initialize a new git repository pub fn init(path: &Path, bare: bool) -> Result { let repo = Git2Repository::init(path, bare)?; Ok(Self { path: path.to_path_buf(), repo }) } /// Open an existing git repository pub fn open(path: &Path) -> Result { let repo = Git2Repository::open(path)?; Ok(Self { path: path.to_path_buf(), repo }) } #[test] fn test_repository_init() { let temp_dir = TempDir::new().unwrap(); let repo_path = temp_dir.path().join("test_repo"); let result = GitRepository::init(&repo_path, false); assert!(result.is_ok()); let repo = result.unwrap(); assert_eq!(repo.path(), repo_path); } #[test] fn test_repository_open_nonexistent() { let temp_dir = TempDir::new().unwrap(); let nonexistent_path = temp_dir.path().join("nonexistent"); let result = GitRepository::open(&nonexistent_path); assert!(result.is_err()); assert!(matches!( result.unwrap_err(), GitRepositoryError::RepositoryNotFound(_) )); } ``` -------------------------------- ### Tsrc Dockerfile Example Source: https://github.com/tk-aria/wmgr/blob/main/README.md This Dockerfile demonstrates how to build a Docker image that includes tsrc. It uses a multi-stage build, first compiling tsrc from source and then copying the binary into a minimal Debian-based runtime image that also includes git. ```dockerfile FROM rust:1.85 as builder WORKDIR /app COPY . . RUN cargo build --release FROM debian:bookworm-slim RUN apt-get update && apt-get install -y git && rm -rf /var/lib/apt/lists/* COPY --from=builder /app/target/release/tsrc /usr/local/bin/ ENTRYPOINT ["tsrc"] ``` -------------------------------- ### Environment Variables in Tsrc Foreach (Bash) Source: https://github.com/tk-aria/wmgr/blob/main/USER_GUIDE.md Demonstrates how to utilize environment variables within tsrc foreach commands for dynamic execution. Includes examples for accessing repository information and conditional command execution. ```bash # Use environment variables in commands tsrc foreach 'echo "Working on $TSRC_REPO_NAME in $TSRC_REPO_PATH"' # Conditional execution tsrc foreach 'if [ -f package.json ]; then npm install; fi' # Generate reports tsrc foreach 'echo "$TSRC_REPO_NAME,$(git rev-parse HEAD)" >> ../report.csv' ``` -------------------------------- ### YAML Manifest Configuration (YAML) Source: https://github.com/tk-aria/wmgr/blob/main/docs/src/wmgr/lib.rs.html This is an example of a YAML manifest file used by wmgr to define the workspace. It specifies repositories, their destinations, URLs, and optional group assignments. ```yaml repos: - dest: "frontend" url: "https://github.com/example/frontend.git" groups: ["web"] - dest: "backend" url: "https://github.com/example/backend.git" groups: ["api"] ``` -------------------------------- ### ManifestStore Initialization Source: https://github.com/tk-aria/wmgr/blob/main/docs/src/wmgr/infrastructure/filesystem/manifest_store.rs.html Provides methods for creating instances of ManifestStore. Supports creation with default settings, custom processing options, or both a custom manifest service and options. This allows flexibility in how manifests are managed. ```rust impl ManifestStore { /// Create a new manifest store with default settings pub fn new() -> Self { Self { manifest_service: ManifestService::default(), options: ManifestProcessingOptions::default(), } } /// Create a new manifest store with custom settings pub fn with_options(options: ManifestProcessingOptions) -> Self { Self { manifest_service: ManifestService::default(), options, } } /// Create a new manifest store with custom manifest service and options pub fn with_service_and_options( manifest_service: ManifestService, options: ManifestProcessingOptions, ) -> Self { Self { manifest_service, options, } } } ``` -------------------------------- ### Pytest Fixtures for Git Project Setup Source: https://github.com/tk-aria/wmgr/blob/main/uithub_tsrc.txt Pytest fixtures to set up a temporary Git project and a bare remote repository for testing. The `git_project` fixture creates a GitProject instance, and `remote_repo` creates a BareRepo instance. ```python @pytest.fixture def git_project(tmp_path: Path, remote_repo: BareRepo) -> GitProject: src_path = tmp_path / "src" src_path.mkdir(parents=True) res = GitProject(src_path, remote_repo) return res @pytest.fixture def remote_repo(tmp_path: Path) -> BareRepo: srv_path = tmp_path / "srv" srv_path.mkdir(parents=True) return BareRepo.create(srv_path, "master", empty=True) ``` -------------------------------- ### Tsrc Manifest Configuration Example Source: https://github.com/tk-aria/wmgr/blob/main/README.md This YAML snippet demonstrates a complete manifest file for tsrc, defining global settings, repository configurations with branches, tags, or SHAs, and optional group definitions for organizing repositories. ```yaml # Global settings defaults: branch: "main" shallow: false # Repository definitions repos: - dest: "backend/api" url: "https://github.com/example/api-server.git" branch: "develop" groups: ["backend", "core"] remotes: - name: "upstream" url: "https://github.com/upstream/api-server.git" - dest: "frontend/web" url: "git@github.com:example/web-app.git" tag: "v2.1.0" groups: ["frontend", "web"] shallow: true - dest: "tools/scripts" url: "https://github.com/example/build-tools.git" sha1: "abc123def456" groups: ["tools"] # Group definitions (optional) groups: core: repos: ["backend/api", "shared/common"] description: "Core infrastructure components" frontend: repos: ["frontend/web", "frontend/mobile"] description: "User-facing applications" tools: repos: ["tools/scripts", "tools/ci"] description: "Development and CI tools" ``` -------------------------------- ### GitHub Actions: Build and Deploy Documentation Source: https://github.com/tk-aria/wmgr/blob/main/uithub_tsrc.txt This workflow builds the project's documentation using MkDocs and deploys it to GitHub Pages. It checks out the code, sets up Python, installs dependencies with Poetry, builds the documentation, and then uses a GitHub Pages deploy action. This workflow runs on pushes to the main branch. ```yaml name: doc on: push: branches: - main jobs: deploy_documentation: runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 - name: Set up Python uses: actions/setup-python@v4 with: python-version: "3.10" - name: Prepare project for development run: | python -m pip install poetry python -m poetry install - name: Build documentation run: | poetry run mkdocs build - name: Deploy to GitHub pages uses: JamesIves/github-pages-deploy-action@v4.6.3 with: token: ${{ secrets.GH_PAT }} branch: gh-pages folder: site ``` -------------------------------- ### Best Practice: Workflow Synchronization and Targeting (Bash) Source: https://github.com/tk-aria/wmgr/blob/main/USER_GUIDE.md Showcases workflow best practices including regular synchronization routines and using groups for targeted operations, such as deploying only production services. Emphasizes efficiency and control. ```bash # Daily sync routine tsrc sync tsrc status # Deploy only production services tsrc foreach "make deploy" --group production ``` -------------------------------- ### Initialize Workspace and Load Manifest in Rust Source: https://github.com/tk-aria/wmgr/blob/main/docs/src/wmgr/presentation/cli/commands/foreach.rs.html This Rust code snippet initializes a workspace, searches for a manifest file (wmgr.yml, wmgr.yaml, manifest.yml, or manifest.yaml) in the current directory and a .wmgr/ subdirectory, and loads its content. It then creates a WorkspaceConfig and updates the workspace status to Initialized, returning the configured workspace. ```rust let mut workspace = Workspace::new(current_dir.clone(), WorkspaceConfig::default_local()); // Use workspace.manifest_file_path() to support wmgr.yml, wmgr.yaml, manifest.yml, manifest.yaml let manifest_file = workspace.manifest_file_path(); if !manifest_file.exists() { return Err(anyhow::anyhow!("Manifest file not found. Tried wmgr.yml, wmgr.yaml, manifest.yml, manifest.yaml in current directory and .wmgr/ subdirectory")); } // Load manifest file use crate::domain::entities::workspace::{WorkspaceConfig, WorkspaceStatus}; use crate::infrastructure::filesystem::manifest_store::ManifestStore; let mut manifest_store = ManifestStore::new(); let processed_manifest = manifest_store .read_manifest(&manifest_file) .await .map_err(|e| anyhow::anyhow!("Failed to read manifest: {}", e))?; // Create workspace config from manifest let workspace_config = WorkspaceConfig::new( "file://".to_string() + &manifest_file.to_string_lossy(), processed_manifest .manifest .default_branch .clone() .unwrap_or_else(|| "main".to_string()), ); let workspace = Workspace::new(current_dir, workspace_config) .with_status(WorkspaceStatus::Initialized) .with_manifest(processed_manifest.manifest); Ok(workspace) ``` -------------------------------- ### Rust: Get TypeId for GitRemoteError Source: https://github.com/tk-aria/wmgr/blob/main/docs/wmgr/infrastructure/git/remote/enum.GitRemoteError.html This implementation of the Any trait provides a method to get the unique TypeId of a GitRemoteError instance. This is useful for runtime type identification. ```rust fn type_id(&self) -> TypeId // Implementation details omitted for brevity ``` -------------------------------- ### Rust: ConfigStore with_config() constructor Source: https://github.com/tk-aria/wmgr/blob/main/docs/src/wmgr/infrastructure/filesystem/config_store.rs.html This Rust code defines the `with_config` associated function for the `ConfigStore` struct, allowing initialization with custom configuration settings. It takes `BackupConfig` and `ValidationConfig` as arguments and returns a new `ConfigStore` instance. This provides flexibility in setting up the configuration store. ```rust pub fn with_config(backup_config: BackupConfig, validation_config: ValidationConfig) -> Self { Self { backup_config, validation_config, } } ``` -------------------------------- ### Rust: Initialize wmgr Workspace Source: https://github.com/tk-aria/wmgr/blob/main/docs/src/wmgr/presentation/cli/commands/init.rs.html This Rust code defines the `InitCommand` struct and its `execute` method. It initializes a new wmgr workspace by creating a configuration file (wmgr.yaml or manifest.yaml) in the specified or current directory. It handles file existence checks, directory creation, and writing default template content. Dependencies include `anyhow`, `std::env`, `std::fs`, and `std::path::PathBuf`. ```rust use crate::common::templates::TemplateProcessor; use anyhow::Result; use std::env; use std::fs; use std::path::PathBuf; /// Initialize a new wmgr workspace pub struct InitCommand { /// Path where to create the wmgr.yaml file pub path: Option, /// Force overwrite existing file pub force: bool, /// Use manifest.yaml instead of wmgr.yaml pub use_manifest_name: bool, } impl InitCommand { pub fn new(path: Option, force: bool, use_manifest_name: bool) -> Self { Self { path, force, use_manifest_name, } } /// Execute the init command pub async fn execute(&self) -> Result<()> { let current_dir = env::current_dir()?; let target_dir = self.path.as_ref().unwrap_or(¤t_dir); // Determine filename based on use_manifest_name flag let filename = if self.use_manifest_name { "manifest.yaml" } else { "wmgr.yaml" }; let target_file = target_dir.join(filename); // Check if file already exists if target_file.exists() && !self.force { return Err(anyhow::anyhow!( "File {} already exists. Use --force to overwrite.", target_file.display() )); } // Create target directory if it doesn't exist if let Some(parent) = target_file.parent() { fs::create_dir_all(parent)?; } // Generate template content let processor = TemplateProcessor::new(); let template_content = processor.get_default_wmgr_template(); // Write template to file fs::write(&target_file, template_content)?; println!("โœ… Successfully created {} template file", filename); println!("๐Ÿ“ Location: {}", target_file.display()); println!(); println!("๐Ÿ“ Next steps:"); println!( " 1. Edit the {} file to configure your repositories", filename ); println!(" 2. Run 'wmgr sync' to clone and sync repositories"); println!(" 3. Use 'wmgr status' to check repository status"); Ok(()) } } ``` -------------------------------- ### Example Usage of with_context (Rust) Source: https://github.com/tk-aria/wmgr/blob/main/docs/src/wmgr/common/result.rs.html This example shows how to use the `with_context` method to add a string context to an existing `TsrcResult` error. It takes an `Err` value and returns a new `TsrcResult` with the added context. ```rust use tsrc::common::result::{TsrcResult, TsrcResultExt}; use tsrc::common::error::TsrcError; let result: TsrcResult = Err(TsrcError::internal_error("original error")); let with_context = result.with_context("operation failed"); assert!(with_context.is_err()); ``` -------------------------------- ### Example Usage of with_internal_error (Rust) Source: https://github.com/tk-aria/wmgr/blob/main/docs/src/wmgr/common/result.rs.html This example demonstrates how to use the `with_internal_error` method to convert a standard `Result` with an `std::io::Error` into a `TsrcResult`, providing a custom error message upon failure. ```rust use tsrc::common::result::{TsrcResult, ResultExt}; use std::fs; let result: Result = Err(std::io::Error::new( std::io::ErrorKind::NotFound, "file not found" )); let tsrc_result: TsrcResult = result.with_internal_error("File operation failed"); assert!(tsrc_result.is_err()); ``` -------------------------------- ### Parse Manifest from File with tsrc Source: https://github.com/tk-aria/wmgr/blob/main/docs/EXAMPLES.md Parses a tsrc manifest file from the local filesystem. It processes the manifest, lists repositories, and reports any warnings encountered. Returns a Result with processed manifest data or a TsrcError. ```rust use tsrc::application::services::manifest_service::ManifestService; use std::path::Path; async fn parse_manifest() -> tsrc::Result<()><{ let service = ManifestService::new(); let processed = service.parse_from_file(Path::new("manifest.yml")).await?; println!("Manifest contains {} repositories", processed.manifest.repos.len()); for repo in &processed.manifest.repos { println!("Repository: {} -> {}", repo.dest, repo.url); if let Some(groups) = &repo.groups { println!(" Groups: {:?}", groups); } } if !processed.warnings.is_empty() { println!("Warnings:"); for warning in &processed.warnings { println!(" - {}", warning); } } Ok(()) } ``` -------------------------------- ### Tsrc Group Operations (Bash) Source: https://github.com/tk-aria/wmgr/blob/main/USER_GUIDE.md Demonstrates various command-line operations using tsrc to interact with repositories based on defined groups. Supports initialization, synchronization, and running commands across grouped repositories. ```bash # Initialize only web repositories tsrc init manifest.yml --group web # Sync only API repositories tsrc sync --group api # Run tests in client repositories tsrc foreach "npm test" --group client # Multiple groups tsrc sync --group web --group api ``` -------------------------------- ### Run Command with Arguments Starting with Hyphen Source: https://github.com/tk-aria/wmgr/blob/main/uithub_tsrc.txt When the command to be executed by `tsrc foreach` includes arguments that start with a hyphen, use the `--` separator to distinguish them from `tsrc`'s own options. This ensures the command is passed correctly to each repository. ```bash $ tsrc foreach -- some-command --with-option ``` -------------------------------- ### Handle Init Command - Rust Source: https://github.com/tk-aria/wmgr/blob/main/docs/wmgr/presentation/cli/struct.CliApp.html Asynchronously handles the initialization command for the CliApp. This method takes an optional path, a force flag, and a flag to use manifest names. It returns a Result indicating the success or failure of the initialization process. ```rust async fn handle_init_command( &self, path: Option<&String>, force: bool, use_manifest_name: bool, ) -> Result<()> ``` -------------------------------- ### Handle Init Command in Rust Source: https://github.com/tk-aria/wmgr/blob/main/docs/src/wmgr/presentation/cli/mod.rs.html Handles the initialization of a new project or workspace. It takes an optional path, a force flag to overwrite existing files, and a flag to use the manifest name for initialization. ```Rust async fn handle_init_command( &self, path: Option<&String>, force: bool, use_manifest_name: bool, ) -> anyhow::Result<()> { use crate::presentation::cli::commands::init::InitCommand; let target_path = path.map(|p| std::path::PathBuf::from(p)); let init_cmd = InitCommand::new(target_path, force, use_manifest_name); init_cmd.execute().await } ``` -------------------------------- ### Rust: Get config.yml File Path Source: https://github.com/tk-aria/wmgr/blob/main/docs/src/wmgr/domain/entities/workspace.rs.html Retrieves the path to the config.yml file. This function first gets the .tsrc directory path and then joins it with "config.yml". It returns a PathBuf representing the location of the configuration file. ```rust /// config.ymlใƒ•ใ‚กใ‚คใƒซใฎใƒ‘ใ‚นใ‚’ๅ–ๅพ— pub fn config_path(&self) -> PathBuf { self.tsrc_dir().join("config.yml") } ``` -------------------------------- ### Load Workspace Configuration (Rust) Source: https://github.com/tk-aria/wmgr/blob/main/docs/src/wmgr/presentation/cli/commands/log.rs.html This Rust code snippet illustrates the process of loading a workspace configuration from the file system. It determines the manifest file path, checks for its existence, and then uses a `ManifestStore` to read and process the manifest file. Error handling is included for cases where the manifest is not found or cannot be read. ```rust /// Load workspace from the current directory async fn load_workspace(&self) -> Result { let current_dir = env::current_dir()?; let workspace = Workspace::new(current_dir.clone(), WorkspaceConfig::default_local()); // Use workspace.manifest_file_path() to support wmgr.yml, wmgr.yaml, manifest.yml, manifest.yaml let manifest_file = workspace.manifest_file_path(); if !manifest_file.exists() { return Err(anyhow::anyhow!("Manifest file not found. Tried wmgr.yml, wmgr.yaml, manifest.yml, manifest.yaml in current directory and .wmgr/ subdirectory")); } // Load manifest file use crate::domain::entities::workspace::{WorkspaceConfig, WorkspaceStatus}; use crate::infrastructure::filesystem::manifest_store::ManifestStore; let mut manifest_store = ManifestStore::new(); let processed_manifest = manifest_store .read_manifest(&manifest_file) .await .map_err(|e| anyhow::anyhow!("Failed to read manifest: {}", e))?; // Create workspace config from manifest let workspace_config = WorkspaceConfig::new( "file://".to_string() + &manifest_file.to_string_lossy(), processed_manifest .manifest .default_branch ``` -------------------------------- ### wmgr Manifest File Example Source: https://github.com/tk-aria/wmgr/blob/main/README.md This YAML snippet defines a wmgr manifest file (`manifest.yml`) which lists repositories to be managed. Each entry specifies the destination path, URL, branch, and groups the repository belongs to. ```yaml repos: - dest: "frontend" url: "https://github.com/example/frontend.git" branch: "main" groups: ["web"] - dest: "backend" url: "https://github.com/example/backend.git" branch: "main" groups: ["api"] - dest: "shared" url: "https://github.com/example/shared.git" branch: "main" groups: ["web", "api"] ``` -------------------------------- ### Tsrc `foreach` Example Output Source: https://github.com/tk-aria/wmgr/blob/main/uithub_tsrc.txt Illustrates the output when running a custom script (e.g., `switch-and-pull`) using `tsrc foreach`. It shows the execution on multiple repositories, including successful operations and error handling for dirty projects. ```text $ tsrc foreach switch-and-pull :: Running `switch-and-pull` on 2 repos * (1/2) foo /path/to/foo $ switch-and-pull Switched to branch 'master' Your branch is behind 'origin/master' by 1 commit, and can be fast-forwarded. (use "git pull" to update your local branch) Updating 9e7a8e4..5f9bbd4 Fast-forward * (2/2) bar /path/to/bar $ switch-and-pull Error: project is dirty Error: Command failed for 1 repo(s) * bar ``` -------------------------------- ### Rust: Examples of Using BranchName Value Object Source: https://github.com/tk-aria/wmgr/blob/main/docs/EXAMPLES.md This Rust code snippet showcases the usage of the `BranchName` value object from the `tsrc` crate. It demonstrates creating a `BranchName` instance, printing its string representation, and checking if it represents a default or a feature branch. ```rust use tsrc::domain::value_objects::branch_name::BranchName; fn branch_name_examples() -> tsrc::Result<()> { let branch = BranchName::new("feature/new-functionality")?; println!("Branch name: {}", branch.as_str()); println!("Is default branch: {}", branch.is_default_branch()); println!("Is feature branch: {}", branch.is_feature_branch()); Ok(()) } ``` -------------------------------- ### Building wmgr from Source (Bash) Source: https://github.com/tk-aria/wmgr/blob/main/README.md Steps to clone the wmgr repository and build the project using Cargo, including development and release builds, running tests, and code formatting. ```bash git clone https://github.com/tk-aria/wmgr.git cd wmgr/v2 # Development build cargo build # Release build with optimizations cargo build --release # Run tests cargo test # Run tests with all features cargo test --all-features # Check code with clippy cargo clippy --all-targets --all-features -- -D warnings # Format code cargo fmt --all ``` -------------------------------- ### Initialize Workspace with Manifest (Bash) Source: https://github.com/tk-aria/wmgr/blob/main/docs/src/wmgr/lib.rs.html This command initializes a new git repository workspace using a provided manifest file. It's a prerequisite for managing repositories with wmgr. ```bash wmgr init manifest.yml ``` -------------------------------- ### CloneToUninit Trait Methods Source: https://github.com/tk-aria/wmgr/blob/main/docs/wmgr/domain/entities/manifest/struct.FileSymlink.html Information about the experimental `CloneToUninit` trait and its `clone_to_uninit` method. ```APIDOC ## unsafe fn clone_to_uninit ### Description Performs copy-assignment from `self` to `dest`. This is a nightly-only experimental API. ### Method POST (or similar for assignment operations) ### Endpoint N/A (Trait Method) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **dest** (*mut u8) - A mutable pointer to the destination buffer. ### Request Example None ### Response #### Success Response (200) None (operation modifies memory directly) ### Response Example None ``` -------------------------------- ### GET /check_local_changes Source: https://github.com/tk-aria/wmgr/blob/main/docs/wmgr/application/use_cases/sync_repositories/struct.SyncRepositoriesUseCase.html Checks if there are any uncommitted local changes in the repository. ```APIDOC ## GET /check_local_changes ### Description Checks if there are any uncommitted local changes in the repository. ### Method GET ### Endpoint /check_local_changes ### Parameters #### Path Parameters None #### Query Parameters - **repo_path** (PathBuf) - Required - The file system path to the repository. ### Request Example ```json { "repo_path": "/path/to/repository" } ``` ### Response #### Success Response (200) - **bool** (boolean) - True if there are local changes, false otherwise. #### Response Example ```json { "has_local_changes": true } ``` ``` -------------------------------- ### Load and Sync Repositories (Rust) Source: https://github.com/tk-aria/wmgr/blob/main/docs/src/wmgr/lib.rs.html This Rust code snippet demonstrates how to programmatically load a workspace from a given path and then synchronize specific groups of repositories. It utilizes the `wmgr` library's use case for syncing. ```rust use wmgr::application::use_cases::sync_repositories::{ SyncRepositoriesUseCase, SyncRepositoriesConfig }; use wmgr::domain::entities::workspace::Workspace; # async fn example() -> wmgr::Result<()> { // Load workspace let workspace = Workspace::load_from_path(".")?; // Create sync configuration let config = SyncRepositoriesConfig::new(".") .with_groups(vec!["web".to_string()]) .with_force(false); // Execute sync let use_case = SyncRepositoriesUseCase::new(config); let result = use_case.execute().await?; println!("Synced {} repositories", result.successful); # Ok(()) # } ``` -------------------------------- ### GET /get_current_branch Source: https://github.com/tk-aria/wmgr/blob/main/docs/wmgr/application/use_cases/sync_repositories/struct.SyncRepositoriesUseCase.html Retrieves the name of the current branch for a given repository. ```APIDOC ## GET /get_current_branch ### Description Retrieves the name of the current branch for a given repository. ### Method GET ### Endpoint /get_current_branch ### Parameters #### Path Parameters None #### Query Parameters - **repo_path** (PathBuf) - Required - The file system path to the repository. ### Request Example ```json { "repo_path": "/path/to/repository" } ``` ### Response #### Success Response (200) - **String** (string) - The name of the current branch. #### Response Example ```json { "current_branch": "main" } ``` ```