update_repo Gem Version Build Status

Dependency Status Coverage Status Code Climate Inline docs PullReview stats

A Simple Gem to keep multiple locally-cloned Git Repositories up to date.

This is the conversion to a Gem of one of my standalone Ruby scripts. Still very much a work in progress but the required basic functionality is there.

Usage

Pre-requirements

It goes without saying that at the very least a working copy of both Git and Ruby need to be installed on your machine. Also, the script has only been tested under Linux, not windows.

Quick start

Create a YAML-formatted configuration file .updaterepo in your home directory that contains at least a 'location' tag pointing to the directory containing the git repositories you wish to have updated :

---
location:
- /media/myuser/git-repos
- /data/RepoDir

This is the most basic example of a configuration file and there are other options that can be added to fine-tune the operation - see the description of configuration options below.

This file should be located in the users home directory (~/.updaterepo).

Run the script :

$ update_repo

Configuration

Configuration file

The configuration file defaults to ~/.updaterepo and is a standard YAML-formatted text file. The first line must contain the YAML frontmatter of 3 dashes (---). After that, the following sections can follow in any order. Only the location: section is compulsory, and that must contain at least one entry.

location: - at least one directory which contains the locally cloned repository(s) to update. There is no limit on how many directories can be listed :

---
location:
- /media/myuser/git-repos
- /data/RepoDir

exceptions: - an (optional) list of repositories that will NOT be updated automatically. Use this for repositories that need special handling, or should only be manually updated. Note that the name specified is that of the directory holding the repository (has the .git directory inside)

exceptions:
- ubuntu-trusty
- update_repo

Command line switches

Options are not required. If none are specified then the program will read from the standard configuration file (~/.updaterepo) and automatically update the specified Repositories.

Enter update_repo --help at the command prompt to get a list of available options :

Options:
  -c, --color, --no-color    Use colored output (default: true)
  -d, --dump                 Dump a list of Directories and Git URL's to STDOUT in CSV format
  -p, --prune=<i>            Number of directory levels to remove from the --dump output.
                             Only valid when --dump or -d specified (Default: 0)
  -i, --import               Import a previous dump of directories and Git repository URL's,
                             (created using --dump) then proceed to clone them locally.
  -v, --version              Print version and exit
  -h, --help                 Show this message

To-Do

Not in any specific order :

  • Improve error-checking and recovery while parsing the configuration file
    • Ignore and report invalid or missing directories
  • Either add an option 'variants' or similar to allow non-standard git pull commands (eg Ubuntu kernel), or update the 'exceptions' option to do same.
  • Error checking and reporting for the git processes [IN PROGRESS]
    • Add more failure cases, not all git errors fail with "fatal:"
  • retry for connection issues etc (config setting).
  • Add extra (optional) stats / info at end-of-job :
    • list of changed repos
    • errors or connection problems [IN PROGRESS]
    • more...
  • Add command line options to override configuration, and even specify an alternate config file. Any options so specified will have precedence over settings specified in the configuration file.
  • Add command line options for verbose or quiet, with same options in config file.
  • Add ability to specify a new directory (containing Git repos) to search from the command line, and optionally save this to the standard configuration.
  • Add new repo from the command line that will be cloned to the default repo directory and then updated as usual. Extra flag added for "add only, clone later" for offline use.
  • Add flag for 'default' repo directory (or another specific directory - if it does not already exist it will be created and added to the standard list) which will be used for new additions.
  • Option to save log file for each run.
  • Add option to only display a (text) tree of the discovered git repositories, not updating them; Similar option to just dump a list of the remote git locations.
  • Add ability to export a text dump of each repo location [DONE] and then re-import this on a different machine or after reinstall [TODO]
  • Document configuration file format and options.
  • Add testing!

Development

After checking out the repo, run bin/setup to install dependencies. Then, run rake spec to run the tests (or simply rake). You can also run bin/console for an interactive prompt that will allow you to experiment.

To install this gem onto your local machine, run bundle exec rake install.

Run rake to run the RSpec tests, which also runs RuboCop, Reek and inch --pedantic too.

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

Please note - This Gem currently aims to pass 100% on RuboCop, Reek and Inch-CI (on pedantic mode), so all pull requests should do likewise. Ask for guidance if needed. Running rake will automatically test all 3 of those along with the RSpec tests. Note that Failures of Rubocop will cause the CI (Travis) to fail, however 'Reek' failures will not.

Versioning

This Gem aims to adhere to Semantic Versioning 2.0.0. Violations of this scheme should be reported as bugs. Specifically, if a minor or patch version is released that breaks backward compatibility, that version should be immediately yanked and/or a new version should be immediately released that restores compatibility. Breaking changes to the public API will only be introduced with new major versions.

Of course, currently we have not even reached version 1, so leave off the version requirement completely. Expect any and all of the API and interface to change!

License

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