Skip to content

Commit 060e64c

Browse files
author
Tobias Meinhardt
committed
New stash and stash pop option in git service
1 parent 26d6690 commit 060e64c

File tree

4 files changed

+46
-0
lines changed

4 files changed

+46
-0
lines changed

git/gogit_adapter.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,16 @@ func (a goGitAdapter) AddAll() error {
117117
return errors.New("not implemented yet")
118118
}
119119

120+
// Stash all changes
121+
func (a goGitAdapter) Stash() error {
122+
return errors.New("not implemented yet")
123+
}
124+
125+
// Pop all stashed changes
126+
func (a goGitAdapter) StashPop() error {
127+
return errors.New("not implemented yet")
128+
}
129+
120130
// Commit added changes
121131
func (a goGitAdapter) Commit(message string) error {
122132
return errors.New("not implemented yet")

git/logging.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,22 @@ func (s loggingService) AddAll() (err error) {
6565
return s.next.AddAll()
6666
}
6767

68+
// Stash all changes
69+
func (s loggingService) Stash() (err error) {
70+
defer func(begin time.Time) {
71+
s.logger.Log("method", "Stash", "took", time.Since(begin), "err", err)
72+
}(time.Now())
73+
return s.next.Stash()
74+
}
75+
76+
// Pop all stashed changes
77+
func (s loggingService) StashPop() (err error) {
78+
defer func(begin time.Time) {
79+
s.logger.Log("method", "StashPop", "took", time.Since(begin), "err", err)
80+
}(time.Now())
81+
return s.next.Stash()
82+
}
83+
6884
// Commit added changes
6985
func (s loggingService) Commit(message string) (err error) {
7086
defer func(begin time.Time) {

git/native_adapter.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,24 @@ func (a nativeGitAdapter) AddAll() error {
8585
return errors.Wrap(err, stderr.String())
8686
}
8787

88+
// Stash all changes
89+
func (a nativeGitAdapter) Stash() error {
90+
cmd := a.exec.Command("git stash")
91+
var stderr bytes.Buffer
92+
cmd.Stderr = &stderr
93+
err := cmd.Run()
94+
return errors.Wrap(err, stderr.String())
95+
}
96+
97+
// Pop all stashed changes
98+
func (a nativeGitAdapter) StashPop() error {
99+
cmd := a.exec.Command("git stash pop")
100+
var stderr bytes.Buffer
101+
cmd.Stderr = &stderr
102+
err := cmd.Run()
103+
return errors.Wrap(err, stderr.String())
104+
}
105+
88106
// Commit added changes
89107
func (a nativeGitAdapter) Commit(message string) error {
90108
cmd := a.exec.Command(fmt.Sprintf("git commit -m '%s'", message))

git/service.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ type Service interface {
1313
BranchList() ([]glow.Branch, error)
1414
Fetch() error
1515
AddAll() error
16+
Stash() error
17+
StashPop() error
1618
Commit(message string) error
1719
Push(setUpstream bool) error
1820
Create(b glow.Branch, skipChecks bool) error

0 commit comments

Comments
 (0)