|
|
|
@ -7,7 +7,7 @@ import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; |
|
|
|
|
import { syncStateContext } from "./sourceControlBase"; |
|
|
|
|
|
|
|
|
|
enum buttonStateValues { |
|
|
|
|
Commit , |
|
|
|
|
Commit, |
|
|
|
|
Sync = 1, |
|
|
|
|
PublishBranch = 2 |
|
|
|
|
} |
|
|
|
@ -24,7 +24,7 @@ export const CommitMessage = () => { |
|
|
|
|
setMessage({ value: e.currentTarget.value }) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const commit = async() => { |
|
|
|
|
const commit = async () => { |
|
|
|
|
if (context.staged.length === 0 && context.allchangesnotstaged.length == 0) return |
|
|
|
|
if (context.staged.length === 0) |
|
|
|
|
await actions.addall(context.allchangesnotstaged) |
|
|
|
@ -36,7 +36,7 @@ export const CommitMessage = () => { |
|
|
|
|
return context.upstream ? context.upstream : context.defaultRemote ? context.defaultRemote : null |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const sync = async() => { |
|
|
|
|
const sync = async () => { |
|
|
|
|
await actions.pull({ |
|
|
|
|
remote: getRemote(), |
|
|
|
|
ref: context.currentBranch |
|
|
|
@ -52,7 +52,7 @@ export const CommitMessage = () => { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const commitNotAllowed = () => { |
|
|
|
|
return context.canCommit === false || message.value === "" || ( context.staged.length === 0 && context.allchangesnotstaged.length == 0 ) |
|
|
|
|
return context.canCommit === false || message.value === "" || (context.staged.length === 0 && context.allchangesnotstaged.length == 0) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const commitMessagePlaceholder = () => { |
|
|
|
@ -68,21 +68,28 @@ export const CommitMessage = () => { |
|
|
|
|
const upDownArrows = () => { |
|
|
|
|
return ( |
|
|
|
|
<> |
|
|
|
|
{syncState.commitsBehind && syncState.commitsBehind.length ? <>{syncState.commitsBehind.length}<FontAwesomeIcon icon={faArrowDown} className="ml-1" /></>: null} |
|
|
|
|
{syncState.commitsAhead && syncState.commitsAhead.length ? <>{syncState.commitsAhead.length}<FontAwesomeIcon icon={faArrowUp} className="ml-1" /></>: null} |
|
|
|
|
{syncState.commitsBehind && syncState.commitsBehind.length ? <>{syncState.commitsBehind.length}<FontAwesomeIcon icon={faArrowDown} className="ml-1" /></> : null} |
|
|
|
|
{syncState.commitsAhead && syncState.commitsAhead.length ? <>{syncState.commitsAhead.length}<FontAwesomeIcon icon={faArrowUp} className="ml-1" /></> : null} |
|
|
|
|
</> |
|
|
|
|
) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const publishEnabled = () => { |
|
|
|
|
const remoteEquivalentBranch = context.branches.find((b) => b.name === context.currentBranch.name && b.remote) |
|
|
|
|
return remoteEquivalentBranch === undefined && getRemote()!== null |
|
|
|
|
return remoteEquivalentBranch === undefined && getRemote() !== null |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const publishBranch = async () => { |
|
|
|
|
if (context.currentBranch === undefined || context.currentBranch.name === "") |
|
|
|
|
return |
|
|
|
|
//await actions.push(context.currentBranch.name)
|
|
|
|
|
await actions.push({ |
|
|
|
|
remote: getRemote(), |
|
|
|
|
ref: context.currentBranch |
|
|
|
|
}) |
|
|
|
|
await actions.pull({ |
|
|
|
|
remote: getRemote(), |
|
|
|
|
ref: context.currentBranch |
|
|
|
|
}) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const messageEnabled = () => { |
|
|
|
@ -91,19 +98,19 @@ export const CommitMessage = () => { |
|
|
|
|
|
|
|
|
|
const setButtonStateValues = () => { |
|
|
|
|
|
|
|
|
|
if (!commitNotAllowed() || context.allchangesnotstaged.length > 0 || context.staged.length > 0){ |
|
|
|
|
if (context.allchangesnotstaged.length == 0 && context.staged.length == 0 && message.value === "" && publishEnabled()){ |
|
|
|
|
if (!commitNotAllowed() || context.allchangesnotstaged.length > 0 || context.staged.length > 0) { |
|
|
|
|
if (context.allchangesnotstaged.length == 0 && context.staged.length == 0 && message.value === "" && publishEnabled()) { |
|
|
|
|
setButtonState(buttonStateValues.PublishBranch) |
|
|
|
|
return |
|
|
|
|
} |
|
|
|
|
setButtonState(buttonStateValues.Commit) |
|
|
|
|
return |
|
|
|
|
} |
|
|
|
|
if (syncEnabled()){ |
|
|
|
|
if (syncEnabled()) { |
|
|
|
|
setButtonState(buttonStateValues.Sync) |
|
|
|
|
return |
|
|
|
|
} |
|
|
|
|
if (publishEnabled()){ |
|
|
|
|
if (publishEnabled()) { |
|
|
|
|
setButtonState(buttonStateValues.PublishBranch) |
|
|
|
|
return |
|
|
|
|
} |
|
|
|
@ -112,24 +119,24 @@ export const CommitMessage = () => { |
|
|
|
|
|
|
|
|
|
useEffect(() => { |
|
|
|
|
setButtonStateValues() |
|
|
|
|
},[context.canCommit, context.staged, context.allchangesnotstaged, context.currentBranch, syncState.commitsAhead, syncState.commitsBehind, message.value]) |
|
|
|
|
}, [context.canCommit, context.staged, context.allchangesnotstaged, context.currentBranch, syncState.commitsAhead, syncState.commitsBehind, message.value]) |
|
|
|
|
|
|
|
|
|
return ( |
|
|
|
|
<> |
|
|
|
|
<div className="form-group"> |
|
|
|
|
<input placeholder={commitMessagePlaceholder()} data-id='commitMessage' disabled={!messageEnabled()} className="form-control" type="text" onChange={handleChange} value={message.value} /> |
|
|
|
|
</div> |
|
|
|
|
<button data-id='commitButton' className={`btn btn-primary w-100 ${buttonState === buttonStateValues.Commit ?'':'d-none'}`} disabled={commitNotAllowed()} onClick={async () => await commit()} > |
|
|
|
|
<button data-id='commitButton' className={`btn btn-primary w-100 ${buttonState === buttonStateValues.Commit ? '' : 'd-none'}`} disabled={commitNotAllowed()} onClick={async () => await commit()} > |
|
|
|
|
<FontAwesomeIcon icon={faCheck} className="mr-1" /> |
|
|
|
|
Commit |
|
|
|
|
Commit |
|
|
|
|
</button> |
|
|
|
|
<button data-id='syncButton' className={`btn btn-primary w-100 ${buttonState === buttonStateValues.Sync ?'':'d-none'}`} disabled={!syncEnabled()} onClick={async () => await sync()} > |
|
|
|
|
<button data-id='syncButton' className={`btn btn-primary w-100 ${buttonState === buttonStateValues.Sync ? '' : 'd-none'}`} disabled={!syncEnabled()} onClick={async () => await sync()} > |
|
|
|
|
<FontAwesomeIcon icon={faSync} className="mr-1" aria-hidden="true" /> |
|
|
|
|
Sync Changes {upDownArrows()} |
|
|
|
|
Sync Changes {upDownArrows()} |
|
|
|
|
</button> |
|
|
|
|
<button data-id='publishBranchButton' className={`btn btn-primary w-100 ${buttonState === buttonStateValues.PublishBranch ?'':'d-none'}`} onClick={async () => await publishBranch()} > |
|
|
|
|
<button data-id='publishBranchButton' className={`btn btn-primary w-100 ${buttonState === buttonStateValues.PublishBranch ? '' : 'd-none'}`} onClick={async () => await publishBranch()} > |
|
|
|
|
<FontAwesomeIcon icon={faCloudArrowUp} className="mr-1" aria-hidden="true" /> |
|
|
|
|
Publish Branch |
|
|
|
|
Publish Branch |
|
|
|
|
</button> |
|
|
|
|
<hr></hr> |
|
|
|
|
</> |
|
|
|
|