gitlab.com/SiaPrime/SiaPrime@v1.4.1/CONTRIBUTING.md (about)

     1  # Contributing to SiaPrime
     2  
     3  #### Table of Contents
     4  - [Contributing to SiaPrime](#Contributing-to-SiaPrime)
     5  			- [Table of Contents](#Table-of-Contents)
     6  	- [Get started with Go](#Get-started-with-Go)
     7  		- [Install Go](#Install-Go)
     8  		- [Learn Go](#Learn-Go)
     9  	- [Build SiaPrime](#Build-SiaPrime)
    10  	- [Contribute to the codebase](#Contribute-to-the-codebase)
    11  		- [Set up git](#Set-up-git)
    12  		- [Fork the SiaPrime repository](#Fork-the-SiaPrime-repository)
    13  		- [Write some code](#Write-some-code)
    14  		- [Submit your code for review](#Submit-your-code-for-review)
    15  		- [More Git resources](#More-Git-resources)
    16  	- [Where to start](#Where-to-start)
    17  	- [Contact us](#Contact-us)
    18  
    19  ## Get started with Go
    20  
    21  ### Install Go
    22  
    23  To install Go on your computer, follow the 
    24  [official installation guide][install-go].  
    25  
    26  You should install the latest [official Go binary][binary] for your system (if 
    27  not available, [install from source][source]).  If you plan to cross compile 
    28  SiaPrime, see [Cross Compilation with Go 1.5][cross] by Dave Cheney.  
    29  
    30  ### Learn Go
    31  
    32  * To get familiar with the language, start with the official [Tour of Go][tour].
    33  * Move onto [How to Write Go Code][how] to learn how to organize Go packages 
    34  and use the go tool.
    35  * Finish with the [Effective Go][effective] guide.
    36  
    37  <a name="build-siaprime"/>
    38  
    39  ## Build SiaPrime
    40  
    41  To build SiaPrime on your machine, enter the following on the command line:
    42  
    43  ```bash
    44  # Download SiaPrime and its dependencies
    45  # Binaries will be installed in $GOPATH/bin
    46  $ go get -u gitlab.com/SiaPrime/SiaPrime/...
    47  
    48  # Switch to directory containing SiaPrime source code
    49  $ cd $GOPATH/src/gitlab.com/SiaPrime/SiaPrime
    50  
    51  # You have three SiaPrime builds to choose from.
    52  # To build the standard release binary:
    53  $ make release
    54  # Or to build the release binary with race detection and an array debugging 
    55  # asserts:
    56  $ make release-race
    57  # Or to build the developer binary (with a different genesis block, faster 
    58  # block times, and other changes):
    59  $ make dev
    60  # Or build the developer binary with race detection:
    61  $ make dev-race
    62  # Build the debugger binary:
    63  $ make debug
    64  # Or build debugger binary with race detection:
    65  $ make debug-race
    66  ```
    67  
    68  ## Contribute to the codebase
    69  
    70  ### Set up git
    71  
    72  Install git on your machine according to [these instructions][install-git] in 
    73  the Pro Git book.
    74  
    75  You will first need to set up global settings using the command line.
    76  ```bash
    77  $ git config --global user.name "Your Name"
    78  $ git config --global user.email you@somedomain.com
    79  
    80  # Tell git to remember your login information for a certain amount of time.
    81  # Default time is 15 minutes:
    82  $ git config --global credential.helper cache
    83  # Or you can choose a different amount of time:
    84  $ git config --global credential.helper "cache --timeout=[seconds]"
    85  
    86  ```
    87  
    88  ### Fork the SiaPrime repository
    89  
    90  While logged into your GitLab account, navigate to the [SiaPrime repository][siaprime] 
    91  and click the 'Fork' button in the upper right hand corner.  Your account now 
    92  has a 'forked' copy of the original repo at 
    93  `https://gitlab.com/<your GitLab username>/SiaPrime`.
    94  
    95  When you installed SiaPrime using `go get`, the go tool put the SiaPrime source code in 
    96  $GOPATH/src/gitlab.com/SiaPrime/SiaPrime. Change to that directory and set up
    97  your fork as a git [remote][remote]:
    98  
    99  ```bash
   100  $ cd $GOPATH/src/gitlab.com/SiaPrime/SiaPrime
   101  # Add your fork as a remote.  Name it whatever is convenient,
   102  # e.g your GitLab username
   103  $ git remote add <remote name> https://gitlab.com/<username>/SiaPrime.git
   104  # Or if you use an SSH key, create the remote with the following
   105  $ git remote add <remote name> git@gitlab.com:<username>/SiaPrime.git
   106  ```
   107  
   108  ### Write some code
   109  
   110  Right now your git local repository only has one branch (called 'master' by 
   111  default). If you want to make changes, add a new branch and make your changes 
   112  there. You should maintain master as an up-to-date copy of the SiaPrime/SiaPrime 
   113  repository's master branch.
   114  
   115  To create and checkout a new branch:
   116  ```bash
   117  # If you're not already in the right directory:
   118  $ cd $GOPATH/src/gitlab.com/SiaPrime/SiaPrime
   119  # Make sure you're on branch master
   120  $ git checkout master
   121  # Create and checkout a new branch
   122  $ git checkout -b <branch>
   123  ```
   124  Now write some code while the new branch is checked out.
   125  
   126  Only implement one logical change per branch. If you're working on several 
   127  things at once, make multiple branches. To switch between branches you're 
   128  working on, you have to stash the changes in the branch you're switching from 
   129  by running `git stash`, which tucks away all changes since the last 
   130  commit.
   131  
   132  ```bash
   133  # Stash changes to current branch.
   134  $ git stash
   135  # Checkout other branch.
   136  $ git checkout <branch>
   137  ...
   138  # Make changes
   139  ...
   140  # Return to first branch:
   141  $ git checkout <branch 1>
   142  # View a list of stashes and their corresponding hashes.
   143  $ git stash list
   144  # Reapply changes from the stash you want to recover and remove that stash from.
   145  # the list
   146  $ git stash pop <hash>
   147  ```
   148  
   149  To learn more about branching, see 
   150  [Using the Fork-and-Branch Git Workflow][branch] and 
   151  [Pro Git - Branches in a Nutshell][nutshell].
   152  For more on stashing, see [Pro Git - Stashing and Cleaning][stashing].
   153    
   154  Be sure to follow the conventions detailed in 
   155  [docs/Developers.md][developers.md].  We will reject merge requests that do not 
   156  satisfy these best practices.
   157  
   158  Once you've finished making changes, stage and commit your changes then update 
   159  your fork on GitLab:
   160  
   161  ```bash
   162  # Make sure the code is up to date with the original repo:
   163  $ git checkout master
   164  $ git pull origin master
   165  # Checkout branch with changes.
   166  $ git checkout <branch>
   167  $ git rebase master
   168  # Before every merge request, you should run `make test-long`
   169  # to test your code and fix formatting and style problems.
   170  $ make test-long
   171  # If all goes well, proceed to staging your changed files:
   172  $ git add <changed files>
   173  # Use `git status` to see what files have been staged.
   174  $ git status
   175  # Commit your changes. If you just run `commit`,  a text editor will pop up for 
   176  # you to enter a description of your changes.
   177  $ git commit -m "Add new tests for CommitSync method"
   178  # Push the changes to your fork on GitLab, which you should have set up as a 
   179  # remote already.
   180  $ git push <fork remote> <branch>
   181  ```
   182  
   183  ### Submit your code for review
   184  
   185  Once you've tested your new code and pushed changes to your fork, navigate to 
   186  your fork at `https://gitlab.com/<username>/Sia` in your browser.  
   187  Switch to the branch you've made changes on by selecting it from the list on 
   188  the upper left.  Then click 'New merge request' on the upper right.
   189  
   190  Once you have made the merge request, we will review your code.  We will reject 
   191  code that is unsafe, difficult to read, or otherwise violates the conventions 
   192  outlined in our [Developers][developers.md] document.
   193  
   194  If you want to tweak code for which you've already submitted a pull request,
   195  push the updated code to your fork with `git push -f <fork remote> <branch>` and
   196  summarize the changes you've made in a comment on the pull request page on 
   197  GitLab.
   198  
   199  Once we have accepted your changes and merged them into the original repo, you 
   200  have some cleanup to do:
   201  
   202  ```bash
   203  # Update local master branch to reflect changes in origin (the original 
   204  # repo).
   205  $ git pull origin master
   206  # Delete the branch you made the pull request from.
   207  $ git branch -d <branch>
   208  # Delete the remote branch on your fork.
   209  $ git push <fork remote> :<branch>
   210  # Update your fork.
   211  $ git push <fork remote> master
   212  ```
   213  
   214  ### More Git resources
   215  
   216    * [How to into git (and GitHub)][luke] by Luke Champine
   217    * [Official resources for learning Git][git]
   218  
   219  ## Where to start
   220  
   221  If you'd like to contribute to SiaPrime but don't have any specific ideas, writing 
   222  tests is a good way to get your feet wet.  See [doc/Running and Writing Tests for SiaPrime.md](Running%20and%20Writing%20Tests%20for%20SiaPrime.md) to get started.
   223  
   224  To learn more about how various parts of the code base work, head over to our [Resources](resources.md) page in our [doc](docs) folder.
   225  
   226  ## Contact us
   227  
   228  Feel free to ask for help on the #general-dev channel on [discord][discord].
   229  
   230  [binary]: https://golang.org/dl/
   231  [source]: https://golang.org/doc/install/source
   232  [tour]: https://tour.golang.org/welcome/1
   233  [how]: https://golang.org/doc/code.html
   234  [luke]: https://gist.github.com/lukechampine/6418449
   235  [git]: https://git-scm.com/doc
   236  [cheney]: http://dave.cheney.net/2013/06/09/writing-table-driven-tests-in-go
   237  [install-go]: https://golang.org/doc/install
   238  [signup]: https://github.com/join?source=header-home
   239  [effective]: https://golang.org/doc/effective_go.html
   240  [siaprime]: https://gitlab.com/SiaPrime/SiaPrime
   241  [branch]: http://blog.scottlowe.org/2015/01/27/using-fork-branch-git-workflow/
   242  [developers.md]: https://gitlab.com/SiaPrime/SiaPrime/blob/master/doc/Developers.md
   243  [gofmt]: https://golang.org/cmd/gofmt/
   244  [nutshell]: https://git-scm.com/book/en/v2/Git-Branching-Branches-in-a-Nutshell
   245  [discord]: https://discord.gg/GkeJ58H
   246  [install-git]: https://git-scm.com/book/en/v2/Getting-Started-Installing-Git
   247  [test-doc]: https://gitlab.com/SiaPrime/SiaPrime/blob/master/doc/Testing.md
   248  [stashing]: https://git-scm.com/book/en/v2/Git-Tools-Stashing-and-Cleaning
   249  [remote]: https://git-scm.com/book/en/v2/Git-Basics-Working-with-Remotes
   250  [sia]: https://gitlab.com/NebulousLabs/Sia
   251  [signup]: https://github.com/join?source=header-home
   252  [source]: https://golang.org/doc/install/source
   253  [stashing]: https://git-scm.com/book/en/v2/Git-Tools-Stashing-and-Cleaning
   254  [test-doc]: https://gitlab.com/NebulousLabs/Sia/blob/master/doc/Testing.md
   255  [tour]: https://tour.golang.org/welcome/1