diff options
Diffstat (limited to 'app/assets/javascripts/ide/stores/mutations.js')
-rw-r--r-- | app/assets/javascripts/ide/stores/mutations.js | 63 |
1 files changed, 61 insertions, 2 deletions
diff --git a/app/assets/javascripts/ide/stores/mutations.js b/app/assets/javascripts/ide/stores/mutations.js index 799c2f51e8d..d0bf847dbde 100644 --- a/app/assets/javascripts/ide/stores/mutations.js +++ b/app/assets/javascripts/ide/stores/mutations.js @@ -131,11 +131,14 @@ export default { }, [types.UPDATE_FILE_AFTER_COMMIT](state, { file, lastCommit }) { const changedFile = state.changedFiles.find(f => f.path === file.path); + const { prevPath } = file; Object.assign(state.entries[file.path], { raw: file.content, changed: !!changedFile, staged: false, + prevPath: '', + moved: false, lastCommit: Object.assign(state.entries[file.path].lastCommit, { id: lastCommit.commit.id, url: lastCommit.commit_path, @@ -144,6 +147,18 @@ export default { updatedAt: lastCommit.commit.authored_date, }), }); + + if (prevPath) { + // Update URLs after file has moved + const regex = new RegExp(`${prevPath}$`); + + Object.assign(state.entries[file.path], { + rawPath: file.rawPath.replace(regex, file.path), + permalink: file.permalink.replace(regex, file.path), + commitsPath: file.commitsPath.replace(regex, file.path), + blamePath: file.blamePath.replace(regex, file.path), + }); + } }, [types.BURST_UNUSED_SEAL](state) { Object.assign(state, { @@ -169,7 +184,11 @@ export default { }, [types.OPEN_NEW_ENTRY_MODAL](state, { type, path }) { Object.assign(state, { - newEntryModal: { type, path }, + entryModal: { + type, + path, + entry: { ...state.entries[path] }, + }, }); }, [types.DELETE_ENTRY](state, path) { @@ -179,8 +198,48 @@ export default { : state.trees[`${state.currentProjectId}/${state.currentBranchId}`]; entry.deleted = true; - state.changedFiles = state.changedFiles.concat(entry); + parent.tree = parent.tree.filter(f => f.path !== entry.path); + + if (entry.type === 'blob') { + state.changedFiles = state.changedFiles.concat(entry); + } + }, + [types.RENAME_ENTRY](state, { path, name, entryPath = null }) { + const oldEntry = state.entries[entryPath || path]; + const nameRegex = + !entryPath && oldEntry.type === 'blob' + ? new RegExp(`${oldEntry.name}$`) + : new RegExp(`^${path}`); + const newPath = oldEntry.path.replace(nameRegex, name); + const parentPath = oldEntry.parentPath ? oldEntry.parentPath.replace(nameRegex, name) : ''; + + state.entries[newPath] = { + ...oldEntry, + id: newPath, + key: `${name}-${oldEntry.type}-${oldEntry.id}`, + path: newPath, + name: entryPath ? oldEntry.name : name, + tempFile: true, + prevPath: oldEntry.path, + url: oldEntry.url.replace(new RegExp(`${oldEntry.path}/?$`), newPath), + tree: [], + parentPath, + raw: '', + }; + oldEntry.moved = true; + oldEntry.movedPath = newPath; + + const parent = parentPath + ? state.entries[parentPath] + : state.trees[`${state.currentProjectId}/${state.currentBranchId}`]; + const newEntry = state.entries[newPath]; + + parent.tree = sortTree(parent.tree.concat(newEntry)); + + if (newEntry.type === 'blob') { + state.changedFiles = state.changedFiles.concat(newEntry); + } }, ...projectMutations, ...mergeRequestMutation, |