mirror of
https://github.com/JanDeDobbeleer/oh-my-posh.git
synced 2024-11-12 14:04:05 -08:00
refactor(git): add booleans to identify state
This commit is contained in:
parent
aa4230fb3f
commit
3d53650b22
|
@ -135,6 +135,11 @@ type Git struct {
|
||||||
IsWorkTree bool
|
IsWorkTree bool
|
||||||
IsBare bool
|
IsBare bool
|
||||||
User *User
|
User *User
|
||||||
|
Detached bool
|
||||||
|
Merge bool
|
||||||
|
Rebase bool
|
||||||
|
CherryPick bool
|
||||||
|
Revert bool
|
||||||
|
|
||||||
// needed for posh-git support
|
// needed for posh-git support
|
||||||
poshgit bool
|
poshgit bool
|
||||||
|
@ -555,6 +560,7 @@ func (g *Git) getGitCommandOutput(args ...string) string {
|
||||||
func (g *Git) setGitHEADContext() {
|
func (g *Git) setGitHEADContext() {
|
||||||
branchIcon := g.props.GetString(BranchIcon, "\uE0A0")
|
branchIcon := g.props.GetString(BranchIcon, "\uE0A0")
|
||||||
if g.Ref == DETACHED {
|
if g.Ref == DETACHED {
|
||||||
|
g.Detached = true
|
||||||
g.setPrettyHEADName()
|
g.setPrettyHEADName()
|
||||||
} else {
|
} else {
|
||||||
head := g.formatHEAD(g.Ref)
|
head := g.formatHEAD(g.Ref)
|
||||||
|
@ -581,6 +587,7 @@ func (g *Git) setGitHEADContext() {
|
||||||
}
|
}
|
||||||
|
|
||||||
if g.env.HasFolder(g.workingDir + "/rebase-merge") {
|
if g.env.HasFolder(g.workingDir + "/rebase-merge") {
|
||||||
|
g.Rebase = true
|
||||||
origin := getPrettyNameOrigin("rebase-merge/head-name")
|
origin := getPrettyNameOrigin("rebase-merge/head-name")
|
||||||
onto := g.getGitRefFileSymbolicName("rebase-merge/onto")
|
onto := g.getGitRefFileSymbolicName("rebase-merge/onto")
|
||||||
onto = g.formatHEAD(onto)
|
onto = g.formatHEAD(onto)
|
||||||
|
@ -590,7 +597,9 @@ func (g *Git) setGitHEADContext() {
|
||||||
g.HEAD = fmt.Sprintf("%s%s onto %s%s (%s/%s) at %s", icon, origin, branchIcon, onto, step, total, g.HEAD)
|
g.HEAD = fmt.Sprintf("%s%s onto %s%s (%s/%s) at %s", icon, origin, branchIcon, onto, step, total, g.HEAD)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if g.env.HasFolder(g.workingDir + "/rebase-apply") {
|
if g.env.HasFolder(g.workingDir + "/rebase-apply") {
|
||||||
|
g.Rebase = true
|
||||||
origin := getPrettyNameOrigin("rebase-apply/head-name")
|
origin := getPrettyNameOrigin("rebase-apply/head-name")
|
||||||
step := g.FileContents(g.workingDir, "rebase-apply/next")
|
step := g.FileContents(g.workingDir, "rebase-apply/next")
|
||||||
total := g.FileContents(g.workingDir, "rebase-apply/last")
|
total := g.FileContents(g.workingDir, "rebase-apply/last")
|
||||||
|
@ -598,9 +607,12 @@ func (g *Git) setGitHEADContext() {
|
||||||
g.HEAD = fmt.Sprintf("%s%s (%s/%s) at %s", icon, origin, step, total, g.HEAD)
|
g.HEAD = fmt.Sprintf("%s%s (%s/%s) at %s", icon, origin, step, total, g.HEAD)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// merge
|
// merge
|
||||||
commitIcon := g.props.GetString(CommitIcon, "\uF417")
|
commitIcon := g.props.GetString(CommitIcon, "\uF417")
|
||||||
|
|
||||||
if g.hasGitFile("MERGE_MSG") {
|
if g.hasGitFile("MERGE_MSG") {
|
||||||
|
g.Merge = true
|
||||||
icon := g.props.GetString(MergeIcon, "\uE727 ")
|
icon := g.props.GetString(MergeIcon, "\uE727 ")
|
||||||
mergeContext := g.FileContents(g.workingDir, "MERGE_MSG")
|
mergeContext := g.FileContents(g.workingDir, "MERGE_MSG")
|
||||||
matches := regex.FindNamedRegexMatch(`Merge (remote-tracking )?(?P<type>branch|commit|tag) '(?P<theirs>.*)'`, mergeContext)
|
matches := regex.FindNamedRegexMatch(`Merge (remote-tracking )?(?P<type>branch|commit|tag) '(?P<theirs>.*)'`, mergeContext)
|
||||||
|
@ -622,23 +634,28 @@ func (g *Git) setGitHEADContext() {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// sequencer status
|
// sequencer status
|
||||||
// see if a cherry-pick or revert is in progress, if the user has committed a
|
// see if a cherry-pick or revert is in progress, if the user has committed a
|
||||||
// conflict resolution with 'git commit' in the middle of a sequence of picks or
|
// conflict resolution with 'git commit' in the middle of a sequence of picks or
|
||||||
// reverts then CHERRY_PICK_HEAD/REVERT_HEAD will not exist so we have to read
|
// reverts then CHERRY_PICK_HEAD/REVERT_HEAD will not exist so we have to read
|
||||||
// the todo file.
|
// the todo file.
|
||||||
if g.hasGitFile("CHERRY_PICK_HEAD") {
|
if g.hasGitFile("CHERRY_PICK_HEAD") {
|
||||||
|
g.CherryPick = true
|
||||||
sha := g.FileContents(g.workingDir, "CHERRY_PICK_HEAD")
|
sha := g.FileContents(g.workingDir, "CHERRY_PICK_HEAD")
|
||||||
cherry := g.props.GetString(CherryPickIcon, "\uE29B ")
|
cherry := g.props.GetString(CherryPickIcon, "\uE29B ")
|
||||||
g.HEAD = fmt.Sprintf("%s%s%s onto %s", cherry, commitIcon, g.formatSHA(sha), formatDetached())
|
g.HEAD = fmt.Sprintf("%s%s%s onto %s", cherry, commitIcon, g.formatSHA(sha), formatDetached())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if g.hasGitFile("REVERT_HEAD") {
|
if g.hasGitFile("REVERT_HEAD") {
|
||||||
|
g.Revert = true
|
||||||
sha := g.FileContents(g.workingDir, "REVERT_HEAD")
|
sha := g.FileContents(g.workingDir, "REVERT_HEAD")
|
||||||
revert := g.props.GetString(RevertIcon, "\uF0E2 ")
|
revert := g.props.GetString(RevertIcon, "\uF0E2 ")
|
||||||
g.HEAD = fmt.Sprintf("%s%s%s onto %s", revert, commitIcon, g.formatSHA(sha), formatDetached())
|
g.HEAD = fmt.Sprintf("%s%s%s onto %s", revert, commitIcon, g.formatSHA(sha), formatDetached())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if g.hasGitFile("sequencer/todo") {
|
if g.hasGitFile("sequencer/todo") {
|
||||||
todo := g.FileContents(g.workingDir, "sequencer/todo")
|
todo := g.FileContents(g.workingDir, "sequencer/todo")
|
||||||
matches := regex.FindNamedRegexMatch(`^(?P<action>p|pick|revert)\s+(?P<sha>\S+)`, todo)
|
matches := regex.FindNamedRegexMatch(`^(?P<action>p|pick|revert)\s+(?P<sha>\S+)`, todo)
|
||||||
|
@ -647,16 +664,19 @@ func (g *Git) setGitHEADContext() {
|
||||||
sha := matches["sha"]
|
sha := matches["sha"]
|
||||||
switch action {
|
switch action {
|
||||||
case "p", "pick":
|
case "p", "pick":
|
||||||
|
g.CherryPick = true
|
||||||
cherry := g.props.GetString(CherryPickIcon, "\uE29B ")
|
cherry := g.props.GetString(CherryPickIcon, "\uE29B ")
|
||||||
g.HEAD = fmt.Sprintf("%s%s%s onto %s", cherry, commitIcon, g.formatSHA(sha), formatDetached())
|
g.HEAD = fmt.Sprintf("%s%s%s onto %s", cherry, commitIcon, g.formatSHA(sha), formatDetached())
|
||||||
return
|
return
|
||||||
case "revert":
|
case "revert":
|
||||||
|
g.Revert = true
|
||||||
revert := g.props.GetString(RevertIcon, "\uF0E2 ")
|
revert := g.props.GetString(RevertIcon, "\uF0E2 ")
|
||||||
g.HEAD = fmt.Sprintf("%s%s%s onto %s", revert, commitIcon, g.formatSHA(sha), formatDetached())
|
g.HEAD = fmt.Sprintf("%s%s%s onto %s", revert, commitIcon, g.formatSHA(sha), formatDetached())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
g.HEAD = formatDetached()
|
g.HEAD = formatDetached()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -116,7 +116,7 @@ You can set the following properties to `true` to enable fetching additional inf
|
||||||
| `gitlab_icon` | `string` | icon/text to display when the upstream is Gitlab - defaults to `\uF296 ` |
|
| `gitlab_icon` | `string` | icon/text to display when the upstream is Gitlab - defaults to `\uF296 ` |
|
||||||
| `bitbucket_icon` | `string` | icon/text to display when the upstream is Bitbucket - defaults to `\uF171 ` |
|
| `bitbucket_icon` | `string` | icon/text to display when the upstream is Bitbucket - defaults to `\uF171 ` |
|
||||||
| `azure_devops_icon` | `string` | icon/text to display when the upstream is Azure DevOps - defaults to `\uEBE8 ` |
|
| `azure_devops_icon` | `string` | icon/text to display when the upstream is Azure DevOps - defaults to `\uEBE8 ` |
|
||||||
| `codecommit_icon` | `string` | icon/text to display when the upstream is AWS CodeCommit - defaults to `\uF270 ` |
|
| `codecommit_icon` | `string` | icon/text to display when the upstream is AWS CodeCommit - defaults to `\uF270 ` |
|
||||||
| `git_icon` | `string` | icon/text to display when the upstream is not known/mapped - defaults to `\uE5FB ` |
|
| `git_icon` | `string` | icon/text to display when the upstream is not known/mapped - defaults to `\uE5FB ` |
|
||||||
| `upstream_icons` | `map[string]string` | a key, value map representing the remote URL (or a part of that URL) and icon to use in case the upstream URL contains the key. These get precedence over the standard icons |
|
| `upstream_icons` | `map[string]string` | a key, value map representing the remote URL (or a part of that URL) and icon to use in case the upstream URL contains the key. These get precedence over the standard icons |
|
||||||
|
|
||||||
|
@ -153,6 +153,11 @@ You can set the following properties to `true` to enable fetching additional inf
|
||||||
| `.Dir` | `string` | the repository's root directory |
|
| `.Dir` | `string` | the repository's root directory |
|
||||||
| `.Kraken` | `string` | a link to the current HEAD in [GitKraken][kraken-ref] for use in [hyperlinks][hyperlinks] in templates `{{ url .HEAD .Kraken }}` |
|
| `.Kraken` | `string` | a link to the current HEAD in [GitKraken][kraken-ref] for use in [hyperlinks][hyperlinks] in templates `{{ url .HEAD .Kraken }}` |
|
||||||
| `.Commit` | `Commit` | HEAD commit information (see below) |
|
| `.Commit` | `Commit` | HEAD commit information (see below) |
|
||||||
|
| `.Detached` | `boolean` | true when the head is detached |
|
||||||
|
| `.Merge` | `boolean` | true when in a merge |
|
||||||
|
| `.Rebase` | `boolean` | true when in a rebase |
|
||||||
|
| `.CherryPick` | `boolean` | true when in a cherry pick |
|
||||||
|
| `.Revert` | `boolean` | true when in a revert |
|
||||||
|
|
||||||
### Status
|
### Status
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue