-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgit-utility.go
More file actions
44 lines (33 loc) · 929 Bytes
/
git-utility.go
File metadata and controls
44 lines (33 loc) · 929 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package main
import (
git "gopkg.in/src-d/go-git.v4"
gitplumming "gopkg.in/src-d/go-git.v4/plumbing"
)
func getSubmodulePathAndHash(gitModule *git.Submodule) (string, gitplumming.Hash, error) {
var (
err error
gitPath string
gitHash gitplumming.Hash
gitSubmoduleStatus *git.SubmoduleStatus
)
if gitSubmoduleStatus, err = gitModule.Status(); err != nil {
return "", gitplumming.Hash{}, err
}
gitPath = gitSubmoduleStatus.Path
gitHash = gitSubmoduleStatus.Current
return gitPath, gitHash, nil
}
func getSubmodulesFromRepositoryPath(gitRepositoryPath string) (git.Submodules, error) {
var (
err error
gitRepository *git.Repository
gitWorktree *git.Worktree
)
if gitRepository, err = git.PlainOpen(gitRepositoryPath); err != nil {
return nil, err
}
if gitWorktree, err = gitRepository.Worktree(); err != nil {
return nil, err
}
return gitWorktree.Submodules()
}