Skip to content

Yangzhen/rebase #31

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Nov 23, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions app/api/gitAPI.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ export function gitGetBranches () {
return request.get(`/git/${config.spaceKey}/branches`)
}

export function gitTags () {
return request.get(`/git/${config.spaceKey}/tags`)
}

export function gitNewBranch (branchName) {
return request.post(`/git/${config.spaceKey}/branches`, {branchName})
}
Expand Down Expand Up @@ -63,10 +67,42 @@ export function gitResetHead ({ref, resetType}) {
return request.post(`/git/${config.spaceKey}/reset`, {ref, resetType})
}

export function gitConflicts ({path}) {
return request.get(`/git/${config.spaceKey}/conflicts`, {path, base64:false})
}

export function gitResolveConflict ({path, content}) {
return request.post(`/git/${config.spaceKey}/conflicts`, {path, content, base64:false})
}

export function gitCancelConflict ({path}) {
return request.delete(`/git/${config.spaceKey}/conflicts`, {path})
}

export function gitRebase ({branch, upstream, interactive, preserve}) {
return request.post(`/git/${config.spaceKey}/rebase`, {branch, upstream, interactive, preserve})
}

export function gitAddTag ({tagName, ref, message, force}) {
return request.post(`/git/${config.spaceKey}/tags`, {tagName, ref, message, force})
}

export function gitMerge (branch) {
return request.post(`/git/${config.spaceKey}/merge`, {name: branch})
}

export function gitRebaseState () {
return request.get(`/git/${config.spaceKey}?state`)
}

export function gitRebaseOperate ({operation, message}) {
return request.post(`/git/${config.spaceKey}/rebase/operate`, {operation, message})
}

export function gitRebaseUpdate (lines) {
return request.postJSON(`/git/${config.spaceKey}/rebase/update`, lines)
}

export function gitCommitDiff ({ref}) {
return request.get(`/git/${config.spaceKey}/diff`, {ref})
}
32 changes: 27 additions & 5 deletions app/commands/commandBindings/git.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,16 @@ export default {

'git:pull': c => $d(Git.pull()),
'git:push': c => $d(Git.push()),
'git:resolve_conflicts': c => {
api.gitStatus().then(({files, clean}) => {
files = _.filter(files, (file) => {
return file.status == 'CONFLICTION'
})
$d(Git.updateStatus({files, isClean: clean}))
}).then(() =>
$d(Modal.showModal('GitResolveConflicts'))
)
},

// 'git:commit_and_push':
'git:new_branch': c => {
Expand All @@ -36,7 +46,6 @@ export default {
)
)
},
// 'git:resolve_conflicts':
'git:stash': c => {
$d(Git.getCurrentBranch()).then(() =>
$d(Modal.showModal('GitStash'))
Expand All @@ -55,8 +64,21 @@ export default {
$d(Modal.showModal('GitResetHead'))
)
},
// 'git:rebase:start':
// 'git:rebase:abort':
// 'git:rebase:continue':
// 'git:rebase:skip_commit':
'git:rebase:start': c => {
$d(Git.getBranches()).then(() => {
$d(Git.getTags())
.then(() =>
$d(Modal.showModal('GitRebaseStart'))
)
})
},
'git:rebase:abort': c => {
$d(Git.gitRebaseOperate({operation: 'ABORT'}))
},
'git:rebase:continue': c => {
$d(Git.gitRebaseOperate({operation: 'CONTINUE'}))
},
'git:rebase:skip_commit': c => {
$d(Git.gitRebaseOperate({operation: 'SKIP'}))
}
}
2 changes: 1 addition & 1 deletion app/components/FileTree/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class FileTree extends Component {
isActive={isContextMenuActive}
pos={contextMenuPos}
context={this.state.contextNode}
deactivate={this.setState.bind(this, {isContextMenuActive: false})} />
deactivate={e => this.setState({isContextMenuActive: false})} />
</div>
)
}
Expand Down
7 changes: 4 additions & 3 deletions app/components/Git/GitCommitView.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,13 @@ import * as GitActions from './actions'
import GitFileTree from './GitFileTree'

var GitCommitView = ({isWorkingDirClean, ...actionProps}) => {
const {updateCommitMessage, commit} = actionProps

const {updateCommitMessage, commit, statusFiles} = actionProps
return isWorkingDirClean ?
<h1 className=''>Your working directory is clean. Nothing to commit.</h1>
: (<div>
<GitFileTree />
<GitFileTree
statusFiles={statusFiles}
/>
<hr />
<div className='git-commit-message-container'>
<textarea name='git-commit-message' id='git-commit-message' rows='4'
Expand Down
49 changes: 34 additions & 15 deletions app/components/Git/GitFileTree.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ class GitFileTree extends Component {
this.state = {
showTreeView: true,
showShrinkPathView: true,
displayOnly: false
displayOnly: this.props.displayOnly || false,
hideTitle: this.props.hideTitle || false,
}
}

Expand All @@ -23,9 +24,12 @@ class GitFileTree extends Component {
<div className='git-filetree-container' tabIndex={1} >
<GitFileTreeNode path='/'
visualParentPath='/'
statusFiles={this.props.statusFiles}
showTreeView={this.state.showTreeView}
showShrinkPathView={this.state.showShrinkPathView}
displayOnly={this.state.displayOnly} />
displayOnly={this.state.displayOnly}
handleClick={this.props.handleClick}
hideTitle={this.state.hideTitle} />
</div>
)
}
Expand All @@ -45,6 +49,8 @@ class _GitFileTreeNode extends Component {
showTreeView,
showShrinkPathView,
visualParentPath, // for usage in shrinkPathView
handleClick,
hideTitle,
...actionProps} = this.props
const {toggleNodeFold, selectNode, toggleStaging} = actionProps

Expand All @@ -67,12 +73,15 @@ class _GitFileTreeNode extends Component {
})}></i>
</span>
}
<span className='filetree-node-label'>File Status
{ displayOnly ? <span> ({node.leafNodes.length} changed) </span>
: <span> ({this.getStagedLeafNodes().length} staged / {node.leafNodes.length} changed) </span>
}
</span>
</div>)
{ hideTitle ? ''
: <span className='filetree-node-label'>File Status
{ displayOnly ? <span> ({node.leafNodes.length} changed) </span>
: <span> ({this.getStagedLeafNodes().length} staged / {node.leafNodes.length} changed) </span>
}
</span>
}
</div>
)

: !showTreeView && node.isDir ? null // flatView

Expand Down Expand Up @@ -105,16 +114,20 @@ class _GitFileTreeNode extends Component {
<span className='filetree-node-icon'>
<i className={cx('fa file-status-indicator', node.status.toLowerCase(), {
'fa-folder-o': node.isDir,
'fa-pencil-square': node.status == 'MODIFIED',
'fa-plus-square': node.status == 'UNTRACKED',
'fa-minus-square': node.status == 'MISSING'
'fa-pencil-square': node.status == 'MODIFIED' || node.status == 'CHANGED',
'fa-plus-square': node.status == 'UNTRACKED' || node.status == 'ADD',
'fa-minus-square': node.status == 'MISSING',
'fa-exclamation-circle': node.status == 'CONFLICTION'
})}></i>
</span>
<span className='filetree-node-label'>
{ showTreeView ?
(node.isDir && showShrinkPathView ?
node.path.replace(visualParentPath, '').replace(/^\//, '')
: node.name)
: (handleClick ?
<label onClick={handleClick.bind(null, node.path)}>{node.name}</label>
: node.name)
)
: node.path}
</span>
<div className='filetree-node-bg'></div>
Expand All @@ -126,13 +139,15 @@ class _GitFileTreeNode extends Component {
<div className={cx('filetree-node-children', {isFolded: node.isFolded})}>
{node.children.map(childNodePath =>
<GitFileTreeNode
statusFiles={statusFiles}
key={childNodePath}
path={childNodePath}
showTreeView={showTreeView}
showShrinkPathView={showShrinkPathView}
visualParentPath={showShrinkPathView && this.shouldHideAtShrinkPath() ? visualParentPath : node.path}
indentCompensation={indentCompensation}
displayOnly={displayOnly} />
displayOnly={displayOnly}
handleClick={handleClick} />
)}
</div>
: null }
Expand Down Expand Up @@ -197,8 +212,12 @@ class _GitFileTreeNode extends Component {
}
const GitFileTreeNode = connect(
(state, ownProps) => ({
statusFiles: state.GitState.statusFiles,
node: state.GitState.statusFiles.get(ownProps.path)
// statusFiles: state.GitState.statusFiles,
statusFiles: ownProps.statusFiles,
node: ownProps.statusFiles.get(ownProps.path),
handleClick: ownProps.handleClick,
displayOnly: ownProps.displayOnly,
hideTitle: ownProps.hideTitle
}),
dispatch => bindActionCreators(GitActions, dispatch)
)(_GitFileTreeNode)
Expand Down
Loading