2015-12-29 20:06:40 +01:00
# Contributing to rclone #
This is a short guide on how to contribute things to rclone.
## Reporting a bug ##
2017-02-11 21:19:44 +01:00
If you've just got a question or aren't sure if you've found a bug
then please use the [rclone forum ](https://forum.rclone.org/ ) instead
of filing an issue.
When filing an issue, please include the following information if
possible as well as a description of the problem. Make sure you test
2017-03-29 14:38:34 +02:00
with the [latest beta of rclone ](https://beta.rclone.org/ ):
2015-12-29 20:06:40 +01:00
* Rclone version (eg output from `rclone -V` )
* Which OS you are using and how many bits (eg Windows 7, 64 bit)
* The command you were trying to run (eg `rclone copy /tmp remote:tmp` )
2017-02-11 21:19:44 +01:00
* A log of the command with the `-vv` flag (eg output from `rclone -vv copy /tmp remote:tmp` )
2015-12-29 20:06:40 +01:00
* if the log contains secrets then edit the file with a text editor first to obscure them
## Submitting a pull request ##
If you find a bug that you'd like to fix, or a new feature that you'd
like to implement then please submit a pull request via Github.
If it is a big feature then make an issue first so it can be discussed.
You'll need a Go environment set up with GOPATH set. See [the Go
getting started docs](https://golang.org/doc/install) for more info.
First in your web browser press the fork button on [rclone's Github
page](https://github.com/ncw/rclone).
Now in your terminal
2018-08-28 16:30:47 +02:00
go get -u github.com/ncw/rclone
2015-12-29 20:06:40 +01:00
cd $GOPATH/src/github.com/ncw/rclone
git remote rename origin upstream
git remote add origin git@github.com:YOURUSER/rclone.git
Make a branch to add your new feature
git checkout -b my-new-feature
And get hacking.
When ready - run the unit tests for the code you changed
go test -v
2017-01-29 10:47:28 +01:00
Note that you may need to make a test remote, eg `TestSwift` for some
2015-12-29 20:06:40 +01:00
of the unit tests.
Note the top level Makefile targets
* make check
* make test
Both of these will be run by Travis when you make a pull request but
2016-11-19 11:09:50 +01:00
you can do this yourself locally too. These require some extra go
packages which you can install with
* make build_dep
2015-12-29 20:06:40 +01:00
Make sure you
2017-01-29 10:47:28 +01:00
* Add documentation for a new feature (see below for where)
2015-12-29 20:06:40 +01:00
* Add unit tests for a new feature
* squash commits down to one per feature
* rebase to master `git rebase master`
When you are done with that
2018-09-04 13:25:16 +02:00
git push origin my-new-feature
2015-12-29 20:06:40 +01:00
Go to the Github website and click [Create pull
request](https://help.github.com/articles/creating-a-pull-request/).
You patch will get reviewed and you might get asked to fix some stuff.
If so, then make the changes in the same branch, squash the commits,
rebase it to master then push it to Github with `--force` .
## Testing ##
rclone's tests are run from the go testing framework, so at the top
level you can run this to run all the tests.
go test -v ./...
rclone contains a mixture of unit tests and integration tests.
Because it is difficult (and in some respects pointless) to test cloud
storage systems by mocking all their interfaces, rclone unit tests can
run against any of the backends. This is done by making specially
named remotes in the default config file.
If you wanted to test changes in the `drive` backend, then you would
need to make a remote called `TestDrive` .
You can then run the unit tests in the drive directory. These tests
are skipped if `TestDrive:` isn't defined.
2018-01-20 10:52:56 +01:00
cd backend/drive
2015-12-29 20:06:40 +01:00
go test -v
You can then run the integration tests which tests all of rclone's
operations. Normally these get run against the local filing system,
but they can be run against any of the remotes.
2018-01-20 10:52:56 +01:00
cd fs/sync
2015-12-29 20:06:40 +01:00
go test -v -remote TestDrive:
go test -v -remote TestDrive: -subdir
2018-01-20 10:52:56 +01:00
cd fs/operations
go test -v -remote TestDrive:
2015-12-29 20:06:40 +01:00
If you want to run all the integration tests against all the remotes,
2018-01-20 10:52:56 +01:00
then change into the project root and run
2015-12-29 20:06:40 +01:00
2018-01-20 10:52:56 +01:00
make test
2015-12-29 20:06:40 +01:00
2018-01-26 10:36:33 +01:00
This command is run daily on the the integration test server. You can
find the results at https://pub.rclone.org/integration-tests/
2018-01-12 17:30:54 +01:00
## Code Organisation ##
Rclone code is organised into a small number of top level directories
with modules beneath.
* backend - the rclone backends for interfacing to cloud providers -
* all - import this to load all the cloud providers
* ...providers
* bin - scripts for use while building or maintaining rclone
* cmd - the rclone commands
* all - import this to load all the commands
* ...commands
* docs - the documentation and website
* content - adjust these docs only - everything else is autogenerated
* fs - main rclone definitions - minimal amount of code
* accounting - bandwidth limiting and statistics
* asyncreader - an io.Reader which reads ahead
* config - manage the config file and flags
* driveletter - detect if a name is a drive letter
* filter - implements include/exclude filtering
* fserrors - rclone specific error handling
* fshttp - http handling for rclone
* fspath - path handling for rclone
* hash - defines rclones hash types and functions
* list - list a remote
* log - logging facilities
* march - iterates directories in lock step
* object - in memory Fs objects
* operations - primitives for sync, eg Copy, Move
* sync - sync directories
* walk - walk a directory
* fstest - provides integration test framework
* fstests - integration tests for the backends
* mockdir - mocks an fs.Directory
* mockobject - mocks an fs.Object
* test_all - Runs integration tests for everything
* graphics - the images used in the website etc
* lib - libraries used by the backend
2018-01-26 10:36:33 +01:00
* atexit - register functions to run when rclone exits
2018-01-12 17:30:54 +01:00
* dircache - directory ID to name caching
* oauthutil - helpers for using oauth
* pacer - retries with backoff and paces operations
* readers - a selection of useful io.Readers
* rest - a thin abstraction over net/http for REST
2018-08-28 16:30:47 +02:00
* vendor - 3rd party code managed by `go mod`
2018-01-12 17:30:54 +01:00
* vfs - Virtual FileSystem layer for implementing rclone mount and similar
2017-01-29 10:47:28 +01:00
## Writing Documentation ##
If you are adding a new feature then please update the documentation.
If you add a new flag, then if it is a general flag, document it in
`docs/content/docs.md` - the flags there are supposed to be in
alphabetical order. If it is a remote specific flag, then document it
in `docs/content/remote.md` .
The only documentation you need to edit are the `docs/content/*.md`
files. The MANUAL.*, rclone.1, web site etc are all auto generated
from those during the release process. See the `make doc` and `make
website` targets in the Makefile if you are interested in how. You
don't need to run these when adding a feature.
Documentation for rclone sub commands is with their code, eg
`cmd/ls/ls.go` .
2015-12-29 20:06:40 +01:00
## Making a release ##
There are separate instructions for making a release in the RELEASE.md
2017-01-29 10:47:28 +01:00
file.
2015-12-29 20:06:40 +01:00
2017-07-23 14:23:42 +02:00
## Commit messages ##
Please make the first line of your commit message a summary of the
change, and prefix it with the directory of the change followed by a
colon. The changelog gets made by looking at just these first lines
so make it good!
If you have more to say about the commit, then enter a blank line and
carry on the description. Remember to say why the change was needed -
the commit itself shows what was changed.
If the change fixes an issue then write `Fixes #1234` in the commit
message. This can be on the subject line if it will fit. If you
don't want to close the associated issue just put `#1234` and the
change will get linked into the issue.
Here is an example of a short commit message:
```
drive: add team drive support - fixes #885
```
And here is an example of a longer one:
```
mount: fix hang on errored upload
In certain circumstances if an upload failed then the mount could hang
indefinitely. This was fixed by closing the read pipe after the Put
completed. This will cause the write side to return a pipe closed
error fixing the hang.
Fixes #1498
```
2017-05-11 16:39:54 +02:00
## Adding a dependency ##
2016-11-19 11:09:50 +01:00
2018-08-28 16:30:47 +02:00
rclone uses the [go
modules](https://tip.golang.org/cmd/go/#hdr-Modules__module_versions__and_more)
support in go1.11 and later to manage its dependencies.
2016-11-19 11:09:50 +01:00
2018-08-28 16:30:47 +02:00
**NB** you must be using go1.11 or above to add a dependency to
rclone. Rclone will still build with older versions of go, but we use
the `go mod` command for dependencies which is only in go1.11 and
above.
2017-05-11 16:39:54 +02:00
2018-08-28 16:30:47 +02:00
rclone can be built with modules outside of the GOPATH, but for
backwards compatibility with older go versions, rclone also maintains
a `vendor` directory with all the external code rclone needs for
building.
The `vendor` directory is entirely managed by the `go mod` tool, do
not add things manually.
To add a dependency `github.com/ncw/new_dependency` see the
instructions below. These will fetch the dependency, add it to
`go.mod` and `go.sum` and vendor it for older go versions.
export GO111MODULE=on
go get github.com/ncw/new_dependency
go mod vendor
2017-05-11 16:39:54 +02:00
2018-08-28 16:30:47 +02:00
You can add constraints on that package when doing `go get` (see the
go docs linked above), but don't unless you really need to.
2017-05-11 16:39:54 +02:00
2018-08-28 16:30:47 +02:00
Please check in the changes generated by `go mod` including the
`vendor` directory and `go.mod` and `go.sum` in a single commit
separate from any other code changes with the title "vendor: add
github.com/ncw/new_dependency". Remember to `git add` any new files
in `vendor` .
2017-05-11 16:39:54 +02:00
## Updating a dependency ##
If you need to update a dependency then run
2018-08-28 16:30:47 +02:00
export GO111MODULE=on
go get -u github.com/pkg/errors
go mod vendor
2017-05-11 16:39:54 +02:00
Check in in a single commit as above.
## Updating all the dependencies ##
In order to update all the dependencies then run `make update` . This
2018-08-28 16:30:47 +02:00
just uses the go modules to update all the modules to their latest
stable release. Check in the changes in a single commit as above.
2017-05-11 16:39:54 +02:00
This should be done early in the release cycle to pick up new versions
of packages in time for them to get some testing.
2017-07-23 14:23:42 +02:00
## Updating a backend ##
If you update a backend then please run the unit tests and the
integration tests for that backend.
Assuming the backend is called `remote` , make create a config entry
called `TestRemote` for the tests to use.
Now `cd remote` and run `go test -v` to run the unit tests.
Then `cd fs` and run `go test -v -remote TestRemote:` to run the
integration tests.
The next section goes into more detail about the tests.
2015-12-29 20:06:40 +01:00
## Writing a new backend ##
Choose a name. The docs here will use `remote` as an example.
Note that in rclone terminology a file system backend is called a
remote or an fs.
Research
* Look at the interfaces defined in `fs/fs.go`
* Study one or more of the existing remotes
Getting going
2018-01-12 17:30:54 +01:00
* Create `backend/remote/remote.go` (copy this from a similar remote)
2017-09-19 17:09:43 +02:00
* box is a good one to start from if you have a directory based remote
2017-07-09 00:31:58 +02:00
* b2 is a good one to start from if you have a bucket based remote
2018-01-12 17:30:54 +01:00
* Add your remote to the imports in `backend/all/all.go`
2017-07-25 16:18:13 +02:00
* HTTP based remotes are easiest to maintain if they use rclone's rest module, but if there is a really good go SDK then use that instead.
2017-09-19 17:09:43 +02:00
* Try to implement as many optional methods as possible as it makes the remote more usable.
2015-12-29 20:06:40 +01:00
Unit tests
* Create a config entry called `TestRemote` for the unit tests to use
2018-04-07 19:48:11 +02:00
* Create a `backend/remote/remote_test.go` - copy and adjust your example remote
2015-12-29 20:06:40 +01:00
* Make sure all tests pass with `go test -v`
Integration tests
2018-01-12 17:30:54 +01:00
* Add your fs to `fstest/test_all/test_all.go`
2015-12-29 20:06:40 +01:00
* Make sure integration tests pass with
2018-01-12 17:30:54 +01:00
* `cd fs/operations`
2017-06-20 16:56:48 +02:00
* `go test -v -remote TestRemote:`
2018-01-26 10:36:33 +01:00
* `cd fs/sync`
* `go test -v -remote TestRemote:`
2017-06-20 16:56:48 +02:00
* If you are making a bucket based remote, then check with this also
2015-12-29 20:06:40 +01:00
* `go test -v -remote TestRemote: -subdir`
2017-06-20 16:56:48 +02:00
* And if your remote defines `ListR` this also
* `go test -v -remote TestRemote: -fast-list`
2015-12-29 20:06:40 +01:00
2018-01-26 10:36:33 +01:00
See the [testing ](#testing ) section for more information on integration tests.
2017-07-09 00:31:58 +02:00
Add your fs to the docs - you'll need to pick an icon for it from [fontawesome ](http://fontawesome.io/icons/ ). Keep lists of remotes in alphabetical order but with the local file system last.
2015-12-29 20:06:40 +01:00
* `README.md` - main Github page
* `docs/content/remote.md` - main docs page
* `docs/content/overview.md` - overview docs
2016-01-07 16:20:32 +01:00
* `docs/content/docs.md` - list of remotes in config section
2015-12-29 20:06:40 +01:00
* `docs/content/about.md` - front page of rclone.org
* `docs/layouts/chrome/navbar.html` - add it to the website navigation
2016-10-04 12:37:31 +02:00
* `bin/make_manual.py` - add the page to the `docs` constant
2017-05-25 10:28:18 +02:00
* `cmd/cmd.go` - the main help for rclone