git-subrepo Documentation

repository·master·Indexed 25 days ago

https://github.com/ingydotnet/git-subrepo

A Git submodule alternative that allows cloning external repositories into subdirectories. It simplifies dependency management by squashing upstream history into single commits in the mainline while allowing collaborators to push and pull changes back to original remotes. The repository also includes Bash+ (a library for enhancing Bash programming) and Test::More/Test::Tap (TAP testing frameworks for Bash).

Tokens
4.8K
Snippets
20
Records
30
Agent score
85%

What's inside git-subrepo

  1. Upgrade git-subrepo

    master

    Upgrade the git-subrepo software.

    If you installed via the .rc file or by modifying your PATH, run:

    git subrepo upgrade

    Alternatively, you can manually pull the latest code from the git-subrepo repository:

    cd /path/to/git-subrepo
    git pull

    If you used make install, you must run make install again after performing a git pull on the source repository.

    git subrepo upgrade
  2. Clone a repository as a subrepo

    master

    Add an external repository as a subrepo in a subdirectory of your current repository. This command fetches the remote repo and merges it into the specified subdirectory. The subrepo history is squashed into a single commit, and a .gitrepo file is created in the subdirectory to track reference information.

    Usage: git subrepo clone <remote-url> [<subdir>] [-b <branch>] [-f] [-m <msg>] [--file=<msg file>] [-e] [--method <merge|rebase>]

    Options:

    • -b <branch>: Specify a branch name.
    • -f (--force): Reclone (completely replace) an existing subdirectory.
    • -m <msg>: Specify a commit message.
    • --file=<msg file>: Use a file for the commit message.
    • -e (--edit): Edit the commit message before committing.
    • --method <merge|rebase>: Decide how the join process is performed (default is merge).
  3. Install Bash+

    master

    Bash+ is a collection of libraries designed to enhance Bash programming. To install it, clone the repository and use the provided Makefile.

    1. Clone the repository: git clone git@github.com:ingydotnet/bashplus
    2. Run tests to ensure everything is working: make test
    3. Install the libraries (you may need sudo depending on your permissions): make install
    git clone git@github.com:ingydotnet/bashplus
    make test
    make install
  4. Enable command completion

    master

    Bash

    1. Ensure Git completion is enabled (e.g., source /etc/bash_completion.d/git).
    2. Source the git-subrepo completion script:
    source /path/to/git-subrepo/share/completion.bash

    Zsh

    Add the completion directory to your fpath in ~/.zshrc before the compinit function is called:

    fpath=('/path/to/git-subrepo/share/zsh-completion' $fpath)
  5. Use Bash+ in your scripts

    master

    Bash+ extends standard Bash by providing libraries for improved programming ergonomics. You can source standard libraries like :std and :array, and use the use keyword to import specific modules. Once imported, module methods can be called using object-oriented syntax (e.g., Module::Name.method).

    source bash+ :std :array
    
    use Foo::Bar this that
    
    Array.new args "$@"
    
    if args.empty?; then
          die "I need args!"
        fi
    
    Foo::Bar.new foo args
    
    this is awesome
  6. Install git-subrepo

    master

    You can install git-subrepo using one of three methods. All methods require first cloning the repository:

    git clone https://github.com/ingydotnet/git-subrepo /path/to/git-subrepo

    Add the following line to your shell startup script (e.g., ~/.bashrc). This modifies your PATH and MANPATH and enables command completion:

    source /path/to/git-subrepo/.rc

    Method 2: Manual PATH configuration

    Manually add the lib and man directories to your environment:

    export GIT_SUBREPO_ROOT="/path/to/git-subrepo"
    export PATH="/path/to/git-subrepo/lib:$PATH"
    export MANPATH="/path/to/git-subrepo/man:$MANPATH"

    Method 3: System install

    Use make install to place the command next to your other git commands. Note that this method does not support the upgrade command or automatic command completion.

    make install

    Requirements: Requires Git version >= 2.23.

    git clone https://github.com/ingydotnet/git-subrepo /path/to/git-subrepo
    echo 'source /path/to/git-subrepo/.rc' >> ~/.bashrc
  7. Write a TAP test file for Bash

    master

    To use Test::More in a Bash script, ensure your script uses the #!/usr/bin/env bash hashbang. You must set up the PATH to include the bin and lib directories of the test-more-bash installation and source the library.

    Example test file structure:

    #!/usr/bin/env bash
    
    # Set up paths to the test-more-bash installation
    TEST_MORE_PATH="/path/to/test-more-bash"
    BASHLIB=`find $TEST_MORE_PATH -type d | grep -E /(bin|lib)$ | xargs -n1 printf "%s:"`
    PATH="$BASHLIB$PATH"
    
    # Load the library
    source bash+ :std
    use Test::More
    
    # Define how many tests to expect
    plan tests 8
    
    # Example test cases
    some-command
    ok $? "some-command is ok"
    pass "This will always pass"
    fail "This will always fail"
    is `echo foo` "foo" "foo is foo"
    isnt foo bar "foo isnt bar"
    like food "foo" "food is like foo"
    unlike team "foo" "There's no foo in team"
    
    # Diagnostic and notes
    diag "A message for stderr"
    note "A message for stdout"
    
    # Array comparison
    output=( $(ls) )
    expected=(README lib bin)
    cmp-array output expected "list files"
  8. Clean up subrepo artifacts

    master

    Remove temporary artifacts created by fetch and branch commands (such as temporary refs, branches, and remotes).

    Usage: git subrepo clean <subdir>|--all|--ALL [-f]

    Options:

    • --all: Clean up after all current subrepos.
    • --ALL: Remove any artifacts that were ever created by subrepo (even if the subrepo no longer exists in the current branch).
    • -f (--force): Force removal of refs.
  9. Bash+ Syntax and Library Usage

    master

    Bash+ provides several ways to import functionality and use enhanced syntax for arrays and object-like structures.

    Importing Libraries

    You can source specific libraries using the source command with colon-separated names:

    source bash+ :std :array

    Alternatively, you can use the use keyword for module-style imports:

    use Foo::Bar this that

    Array and Object Patterns

    Bash+ introduces patterns for handling arguments and creating new objects:

    • Array Initialization: Array.new args "$@"
    • Conditional Checks: if args.empty?; then ... fi
    • Object Instantiation: Foo::Bar.new foo args
    • Imported Commands: Once a library is imported, its functions can be called directly as standard commands (e.g., this is awesome).
    source bash+ :std :array
    
    use Foo::Bar this that
    
    Array.new args "$@"
    
    if args.empty?; then
      die "I need args!"
    fi
    
    Foo::Bar.new foo args
    
    this is awesome