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