Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

git_tree

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

git_tree

  • 0.2.3
  • Rubygems
  • Socket score

Version published
Maintainers
1
Created
Source

Git_tree Gem Version

This Ruby gem installs two commands that scan a git directory tree and write out scripts. Directories containing a file called .ignore are ignored.

  • The git-tree-replicate command writes a script that clones the repos in the tree, and adds any defined remotes.

    • Any git repos that have already been cloned into the target directory tree are skipped. This means you can rerun git-tree-replicate as many times as you want, without ill effects.
    • All remotes in each repo are replicated.
  • The git-tree-evars command writes a script that defines environment variables pointing to git repos.

Usage

Both commands require one environment variable reference to be passed to them. Enclose the name of the environment variable within single quotes, which will prevent the shell from expanding it before invoking the command.

git-tree-replicate Usage

The following creates a script in the current directory called work.sh, that replicates the desired portions of the directory tree of git repos pointed to by $work:

$ git-tree-replicate '$work' > work.sh

The generated environment variables will all be relative to the path pointed to by the expanded environment variable that you provided. You will understand what this means once you look at the generated script.

When git-tree-replicate completes, edit the generated script to suit, then copy it to the target machine and run it. The following example copies the script to machine2 and runs it:

$ scp work.sh machine2:

$ ssh machine2 work.sh

Generated Script from git-tree-replicate

Following is a sample of one section, which is repeated for every git repo that is processed: You can edit them to suit.

if [ ! -d "sinatra/sinatras-skeleton/.git" ]; then
  mkdir -p 'sinatra'
  pushd 'sinatra' > /dev/null
  git clone git@github.com:mslinn/sinatras-skeleton.git
  git remote add upstream 'https://github.com/simonneutert/sinatras-skeleton.git'
  popd > /dev/null
fi

git-tree-evars Usage

The git-tree-evars command should be run on the target computer. The command requires only one parameter: an environment variable reference, pointing to the top-level directory to replicate. The environment variable reference must be contained within single quotes to prevent expansion by the shell.

The following appends to any script in the $work directory called .evars. The script defines environment variables that point to each git repos pointed to by $work:

$ git-tree-evars '$work' >> $work/.evars

Generated Script from git-tree-evars

Following is a sample of environment variable definitions. You are expected to edit it to suit.

export work=/mnt/c/work
export ancientWarmth=$work/ancientWarmth/ancientWarmth
export ancientWarmthBackend=$work/ancientWarmth/ancientWarmthBackend
export braintreeTutorial=$work/ancientWarmth/braintreeTutorial
export survey_analytics=$work/ancientWarmth/survey-analytics
export survey_creator=$work/ancientWarmth/survey-creator
export django=$work/django/django
export frobshop=$work/django/frobshop

The environment variable definitions are meant to be saved into a file that is sourced upon boot. While you could place them in a file like ~/.bashrc, the author's preference is to instead place them in $work/.evars, and add the following to ~/.bashrc:

source "$work/.evars"

Thus each time you log in, the environment variable definitions will have been re-established. You can therefore change directory to any of the cloned projects, like this:

$ cd $git_root

$ cd $my_project

Installation

Type the following at a shell prompt on the machine you are copying the git tree from, and on the machine that you are copying the git tree to:

$ yes | sudo apt install cmake libgit2-dev libssh2-1-dev pkg-config

$ gem install git_tree

To register the new commands, either log out and log back in, or open a new console.

Additional Information

More information is available on Mike Slinn’s website

Development

After checking out the repo, run bin/setup to install dependencies.

Run the following to create a directory tree for testing.

$ ruby bin/make_test_directory.rb

You can run bin/console for an interactive prompt that will allow you to experiment.

$ bin/console
irb(main):001:0> GitTree.command_replicate 'demo'

irb(main):002:0> GitTree.command_evars 'demo'

Build and Install Locally

To build and install this gem onto your local machine, run:

$ bundle exec rake install

Examine the newly built gem:

$ gem info git_tree

*** LOCAL GEMS ***
git_tree (0.2.0)
    Author: Mike Slinn
    Homepage:
    https://github.com/mslinn/git_tree_replicate
    License: MIT
    Installed at: /home/mslinn/.gems

Build and Push to RubyGems

To release a new version,

  1. Update the version number in version.rb.
  2. Commit all changes to git; if you don't the next step might fail with an unexplainable error message.
  3. Run the following:
    $ bundle exec rake release
    
    The above creates a git tag for the version, commits the created tag, and pushes the new .gem file to RubyGems.org.

Contributing

  1. Fork the project
  2. Create a descriptively named feature branch
  3. Add your feature
  4. Submit a pull request

License

The gem is available as open source under the terms of the MIT License.

FAQs

Package last updated on 26 May 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc