Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Hank Chan committed Nov 11, 2018
0 parents commit e0223ef
Show file tree
Hide file tree
Showing 8 changed files with 1,317 additions and 0 deletions.
61 changes: 61 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*

# Runtime data
pids
*.pid
*.seed
*.pid.lock

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage

# nyc test coverage
.nyc_output

# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# Bower dependency directory (https://bower.io/)
bower_components

# node-waf configuration
.lock-wscript

# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release

# Dependency directories
node_modules/
jspm_packages/

# TypeScript v1 declaration files
typings/

# Optional npm cache directory
.npm

# Optional eslint cache
.eslintcache

# Optional REPL history
.node_repl_history

# Output of 'npm pack'
*.tgz

# Yarn Integrity file
.yarn-integrity

# dotenv environment variables file
.env

# next.js build output
.next
11 changes: 11 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
sudo: false

language: bash

# Trigger Travis CI only when master branch is pushed, ignoring develop branch
branches:
only:
- master

script:
- bash -c 'echo 'complete''
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2018 Hank Chan

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:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

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.
27 changes: 27 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# git-stack    ![GitHub tag (latest SemVer)](https://img.shields.io/github/tag/hankchanocd/git-stack.svg) [![Build Status](https://travis-ci.org/hankchanocd/git-stack.svg?branch=master)](https://travis-ci.org/hankchanocd/git-stack) [![Commitizen friendly](https://img.shields.io/badge/commitizen-friendly-brightgreen.svg)](http://commitizen.github.io/cz-cli/) [![Github issues](https://img.shields.io/github/issues/hankchanocd/git-stack.svg)](https://github.com/hankchanocd/git-stack/issues) [![CodeFactor](https://www.codefactor.io/repository/github/hankchanocd/git-stack/badge)](https://www.codefactor.io/repository/github/hankchanocd/git-stack)

> View difference between git branches
`git stack`.

## Install

Clone the repo, and run `npm run transfer` to transfer `./git-stack` to `~/bin`, or manually invoke `./script/transfer.sh`. If you have a more desired `PATH` for storing scripts, configure `./script/transfer.sh` directly.

## Before-Use

Make sure [`fzf`](https://github.com/junegunn/fzf) is installed globally. `git stack` won't work if `fzf` is not installed.

## Usage

```bash
$ git stack
```

## Changelog

**2018-Nov-11:** `v1` published. Automate commit and file transfer process with [`commitizen`](http://commitizen.github.io/cz-cli/) and [`ghooks`](https://github.com/ghooks-org/ghooks).

## License

[MIT](./LICENSE)
43 changes: 43 additions & 0 deletions git-stack
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#!/usr/bin/env bash
#!/usr/bin/env zsh
#
# Show the difference between the selected branch and master branch

function stack() {
# Check if it's a git repo
[[ $(git root 2>&1) == 'Not a git repo!' ]] && echo "Not a git repo!" && exit 1

branch=''
# Select a branch if no 'develop' branch
if [[ -z $(git branch --list | grep 'develop') ]]; then
branch=$(git branch --list |
grep --invert-match 'master' | # Remove master from options
fzf --reverse --height=40% --cycle |
tr "*" " " |
xargs) # Remove trailing whitespaces
else
branch='develop'
fi

# Check if $branch has value
[[ -z "$branch" ]] && echo "No branch selected" && exit 1

function fuzzy-commit() {
function glNoGraph() {
git log master.."$branch" --color=always --format="%C(auto)%h%d %s %C(black)%C(bold)%cr% C(auto)%an" "$@"
}
_gitLogLineToHash="echo {} | grep -o '[a-f0-9]\{7\}' | head -1"
_viewGitLogLine="$_gitLogLineToHash | xargs -I % sh -c 'git show --color=always % | diff-so-fancy'"

glNoGraph |
fzf --cycle --no-sort --reverse --tiebreak=index --no-multi \
--ansi --preview="$_viewGitLogLine" \
--header "enter to view, alt-y to copy hash" \
--bind "enter:execute:$_viewGitLogLine | less -R" \
--bind "alt-y:execute:$_gitLogLineToHash | xclip"
}

fuzzy-commit
}

stack
Loading

0 comments on commit e0223ef

Please sign in to comment.