Skip to content

Commit

Permalink
add hunk staging, branch sorting and contribution guide (#39)
Browse files Browse the repository at this point in the history
* diff of staged files can be seen now

* update readme

* add hunk staging feature

* bump version

* simplified status entries

* update status

* add hunk unstage

* adjust navigation on hunk staging

* Update README.md

Co-Authored-By: isacikgoz <serdaracikgoz86@gmail.com>

* restore diffparser

* add contribution link to readme

* fix license type in the readme

* add option to load branches by date

* add controls view and improve ui

* add comments to editor files
  • Loading branch information
isacikgoz authored Feb 11, 2019
1 parent 94a9575 commit c3f12e3
Show file tree
Hide file tree
Showing 11 changed files with 1,067 additions and 122 deletions.
42 changes: 25 additions & 17 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,21 +1,29 @@
MIT License
BSD 3-Clause License

Copyright (c) 2019 Ibrahim Serdar Acikgoz
Copyright (c) 2019, Ibrahim Serdar Acikgoz
All rights reserved.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
* Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.

* Neither the name of the copyright holder nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 changes: 22 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

`gitin` is a commit/branch/status explorer for `git`

gitin is a minimalist tool that lets you explore a git repository from command line. You can search from commits, inspect indvidual files and changes in the commits, see ahead/behind commits etc. It is an alternative and interactive way to explore the commit history. Also, you can explore your current state by investigating diffs, stage your changes and commit them.
gitin is a minimalist tool that lets you explore a git repository from the command line. You can search from commits, inspect individual files and changes in the commits, see ahead/behind commits etc. It is an alternative and interactive way to explore the commit history. Also, you can explore your current state by investigating diffs, stage your changes and commit them.

<p align="center">
<img src="https://github.com/isacikgoz/gitin/blob/master/img/screencast.gif" alt="screencast"/>
Expand All @@ -15,7 +15,7 @@ gitin is a minimalist tool that lets you explore a git repository from command l
- `cd` into `$GOPATH/src/github.com/isacikgoz/gitin`
- build with `make install` (`cmake` and `pkg-config` are required)

### Mac using brew
### Mac using brew
```
brew tap isacikgoz/gitin
brew install gitin
Expand All @@ -40,27 +40,35 @@ Commands:
Show commit logs.

status
Show working-tree status. Also stage and commit changes.
Show working-tree status. Also, stage and commit changes.

```

## Configure
- To set line size `export GITIN_LINESIZE=5`
- To set the line size `export GITIN_LINESIZE=5`
- To hide help `export GITIN_HIDEHELP=true`

## Development Requirements
- Requires gitlib2 v27 and `git2go`. See the project homepages for build instructions.
1. download git2go; `go get -d gopkg.in/libgit2/git2go.v27`
2. make sure you have `cmake`, `pkg-confid` and `libssl-dev` installed
3. `cd` into `$GOPATH/src/gopkg.in/libgit2/git2go.v27`
4. initialize submodules by running `git submodule update --init`
5. change the libigt2 version to your version (in this case its 0.27) in the install script (`script/install-libgit2.sh`)
6. run the script `./script/install-libgit2.sh`
- Requires gitlib2 v27 and `git2go`. See the project homepages for more information about build instructions. For gitin you can simply;
- macOS:
1. install libgit2 via `brew install libgit2` (consider that libgit2.v27 is required)
- Linux and macOS(if you want to build your own):
1. download git2go; `go get -d gopkg.in/libgit2/git2go.v27`
2. make sure you have `cmake`, `pkg-config` and `libssl-dev` installed
3. `cd` into `$GOPATH/src/gopkg.in/libgit2/git2go.v27`
4. initialize submodules by running `git submodule update --init`
5. change the libigt2 version to your version (in this case its 0.27) in the install script (e.g. `nano script/install-libgit2.sh` or `vim script/install-libgit2.sh`) and change `LG2VER` to 0.27.0
6. run the script `./script/install-libgit2.sh`
- After these you can download it with `go get github.com/isacikgoz/gitin`
- `cd` into `$GOPATH/src/github.com/isacikgoz/gitin` and start hacking

## Disclaimer
This project is at very early stage of the development and there may be a few bugs. Consider reporting them by raising an issue.
## Contribution
- Contributions are welcome. If you like to please refer to [Contribution Guidelines](/CONTRIBUTING.md)
- Bug reports should include descriptive steps to reproduce so that maintainers can easily understand the actual problem
- Feature requests are welcome, ask for anything that seems appropriate

## Credits
- See the [credits page](https://github.com/isacikgoz/gitin/wiki/Credits)

## License
[MIT](/LICENSE)
[BSD-3-Clause](/LICENSE)
31 changes: 31 additions & 0 deletions cli/branch.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"os"
"os/exec"
"sort"
"strings"

"github.com/isacikgoz/gitin/git"
Expand All @@ -14,6 +15,7 @@ import (

type BranchOptions struct {
Types BranchTypes
Sort BranchSortTypes
PromptOps *PromptOptions
}

Expand All @@ -25,6 +27,13 @@ const (
AllBranches
)

type BranchSortTypes uint8

const (
BranchSortDefault BranchSortTypes = iota
BranchSortDate
)

func BranchBuilder(r *git.Repository, opts *BranchOptions) error {
if err := r.InitializeBranches(); err != nil {
return err
Expand All @@ -50,6 +59,13 @@ func BranchBuilder(r *git.Repository, opts *BranchOptions) error {
r.Branches = r.Branches[:i]
case AllBranches:

}

switch opts.Sort {
case BranchSortDate:
sort.Sort(BranchesByDate(r.Branches))
default:

}
return branchPrompt(r, opts.PromptOps)
}
Expand Down Expand Up @@ -156,3 +172,18 @@ func deleteBranch(r *git.Repository, b *git.Branch, mode string) error {
}
return nil
}

// BranchesByDate slice is the re-ordered *git.Branch slice that sorted according
// to modification date
type BranchesByDate []*git.Branch

// Len is the interface implementation for BranchesByDate sorting function
func (s BranchesByDate) Len() int { return len(s) }

// Swap is the interface implementation for BranchesByDate sorting function
func (s BranchesByDate) Swap(i, j int) { s[i], s[j] = s[j], s[i] }

// Less is the interface implementation for BranchesByDate sorting function
func (s BranchesByDate) Less(i, j int) bool {
return s[i].Date().Unix() > s[j].Date().Unix()
}
Loading

0 comments on commit c3f12e3

Please sign in to comment.