Skip to content

Commit

Permalink
restore tags and fix linewrap after quit
Browse files Browse the repository at this point in the history
* ressurected tags feature

* fix restoring linewrap after quit (#33)

* bump version

* add force delete feature to gitin branch
  • Loading branch information
isacikgoz authored Feb 8, 2019
1 parent 49e903c commit 604a2ea
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 45 deletions.
33 changes: 26 additions & 7 deletions cli/branch.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (

"github.com/isacikgoz/gitin/git"
"github.com/isacikgoz/promptui"
"github.com/isacikgoz/promptui/screenbuf"

log "github.com/sirupsen/logrus"
)
Expand Down Expand Up @@ -76,14 +75,26 @@ func branchPrompt(r *git.Repository, opts *PromptOptions) error {
return nil
}
kset['d'] = func(in interface{}, chb chan bool, index int) error {
screenbuf.Clear(os.Stdin)
b := r.Branches[index]
if b == r.Branch {
return nil
}
cmd := exec.Command("git", "branch", "-d", b.Name)
cmd.Dir = r.AbsPath
if err := cmd.Run(); err == nil {
if err := deleteBranch(r, b, "d"); err != nil {
log.Error(err)
}
chb <- false
if err := r.InitializeBranches(); err != nil {
return err
}
prompt.RefreshList(r.Branches, index)
return nil
}
kset['D'] = func(in interface{}, chb chan bool, index int) error {
b := r.Branches[index]
if b == r.Branch {
return nil
}
if err := deleteBranch(r, b, "D"); err != nil {
log.Error(err)
}
chb <- false
Expand All @@ -106,7 +117,6 @@ func branchPrompt(r *git.Repository, opts *PromptOptions) error {
i, _, err := prompt.RunCursorAt(opts.Cursor, opts.Scroll)

if err == nil {
screenbuf.Clear(os.Stdin)
cmd := exec.Command("git", "checkout", r.Branches[i].Name)
cmd.Dir = r.AbsPath
cmd.Stdout = os.Stdout
Expand All @@ -115,7 +125,7 @@ func branchPrompt(r *git.Repository, opts *PromptOptions) error {
return cmd.Run()
}

return screenbuf.Clear(os.Stdin)
return nil
}

func branchTemplate() *promptui.SelectTemplates {
Expand All @@ -137,3 +147,12 @@ func branchTemplate() *promptui.SelectTemplates {
}
return templates
}

func deleteBranch(r *git.Repository, b *git.Branch, mode string) error {
cmd := exec.Command("git", "branch", "-"+mode, b.Name)
cmd.Dir = r.AbsPath
if err := cmd.Run(); err == nil {
return err
}
return nil
}
4 changes: 0 additions & 4 deletions cli/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,10 @@ package cli
import (
"errors"
"fmt"
"os"
"strings"

"github.com/isacikgoz/gitin/git"
"github.com/isacikgoz/promptui"
"github.com/isacikgoz/promptui/screenbuf"
)

type LogOptions struct {
Expand Down Expand Up @@ -98,7 +96,6 @@ func logPrompt(r *git.Repository, opts *PromptOptions, commits []*git.Commit) er
return nil
}
kset['s'] = func(in interface{}, chb chan bool, index int) error {
screenbuf.Clear(os.Stdin)
if err := emuEnterKey(); err != nil {
chb <- true
} else {
Expand All @@ -117,7 +114,6 @@ func logPrompt(r *git.Repository, opts *PromptOptions, commits []*git.Commit) er
return logPrompt(r, o, commits)
}
kset['d'] = func(in interface{}, chb chan bool, index int) error {
screenbuf.Clear(os.Stdin)
if err := emuEnterKey(); err != nil {
chb <- true
} else {
Expand Down
5 changes: 3 additions & 2 deletions cli/prompt.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,10 @@ func emuEnterKey() error {
}

func quitPrompt(r *git.Repository, chb chan bool) {
defer os.Exit(0)
r.Close()

chb <- true
// sorry to steal 100 ms, lets give it to readline to close itself
// lets give it to readline to close itself
time.Sleep(100 * time.Millisecond)
os.Exit(0)
}
4 changes: 0 additions & 4 deletions cli/stat.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
package cli

import (
"os"

"github.com/isacikgoz/gitin/git"
"github.com/isacikgoz/promptui"
"github.com/isacikgoz/promptui/screenbuf"
)

func statPrompt(r *git.Repository, c *git.Commit, opts *PromptOptions) error {
Expand All @@ -17,7 +14,6 @@ func statPrompt(r *git.Repository, c *git.Commit, opts *PromptOptions) error {
deltas := diff.Deltas()
kset := make(map[rune]promptui.CustomFunc)
kset['q'] = func(in interface{}, chb chan bool, index int) error {
screenbuf.Clear(os.Stdin)
if err := emuEnterKey(); err != nil {
chb <- true
} else {
Expand Down
2 changes: 1 addition & 1 deletion git/commit.go
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,7 @@ func signaturefilter(opts *CommitLoadOptions) bool {
func (c *Commit) Decoration() string {
var decor string
if c.Tag != nil {
decor = "(tag: " + c.Tag.Name + ")"
decor = "(tag: " + c.Tag.Shorthand + ")"
}
return decor
}
Expand Down
40 changes: 14 additions & 26 deletions git/tag.go
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
package git

import (
lib "gopkg.in/libgit2/git2go.v27"
)

// Tag is used to label and mark a specific commit in the history.
// It is usually used to mark release points
type Tag struct {
Hash string
Target *lib.Oid
Tagger *Contributor
Name string
Message string
Hash string
// Target *lib.Oid
// Tagger *Contributor
Shorthand string
Name string
// Message string
}

// loadTags loads tags from the refs
Expand All @@ -30,24 +27,15 @@ func (r *Repository) loadTags() ([]*Tag, error) {
break
}

if ref.IsTag() {
tag, err := r.repo.LookupTag(ref.Target())
if err != nil {
if !ref.IsRemote() && ref.IsTag() {

} else {
t := &Tag{
Hash: tag.Id().String(),
Target: tag.Target().Id(),
Name: tag.Name(),
Message: tag.Message(),
Tagger: &Contributor{
Name: tag.Tagger().Name,
Email: tag.Tagger().Email,
When: tag.Tagger().When,
},
}
ts = append(ts, t)
t := &Tag{
Hash: ref.Target().String(),
Name: ref.Name(),
Shorthand: ref.Shorthand(),
}
ts = append(ts, t)

}
}
r.Tags = ts
Expand All @@ -58,7 +46,7 @@ func (r *Repository) loadTags() ([]*Tag, error) {
// this is a performance killer implementation. FIXME
func (r *Repository) findTag(hash string) *Tag {
for _, t := range r.Tags {
if t.Target.String()[:7] == hash[:7] {
if t.Hash[:7] == hash[:7] {
return t
}
}
Expand Down
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ var (

func main() {

pin.Version("gitin version 0.1.2")
pin.Version("gitin version 0.1.3")
pin.CommandLine.HelpFlag.Short('h')
pin.CommandLine.VersionFlag.Short('v')
pin.Parse()
Expand Down

0 comments on commit 604a2ea

Please sign in to comment.