Commit 89c56c1f authored by Phil Hughes's avatar Phil Hughes

fixed folders not being renamed

parent e7fe50bf
...@@ -193,7 +193,7 @@ export default { ...@@ -193,7 +193,7 @@ export default {
data-container="body" data-container="body"
data-placement="right" data-placement="right"
name="file-modified" name="file-modified"
css-classes="prepend-left-5 multi-file-modified" css-classes="prepend-left-5 ide-file-modified"
/> />
</span> </span>
<changed-file-icon <changed-file-icon
......
...@@ -193,9 +193,16 @@ export const deleteEntry = ({ commit, dispatch, state }, path) => { ...@@ -193,9 +193,16 @@ export const deleteEntry = ({ commit, dispatch, state }, path) => {
export const resetOpenFiles = ({ commit }) => commit(types.RESET_OPEN_FILES); export const resetOpenFiles = ({ commit }) => commit(types.RESET_OPEN_FILES);
export const renameEntry = ({ dispatch, commit }, { path, name }) => { export const renameEntry = ({ dispatch, commit, state }, { path, name, entryPath = null }) => {
commit(types.RENAME_ENTRY, { path, name }); commit(types.RENAME_ENTRY, { path, name, entryPath });
dispatch('deleteEntry', path);
state.entries[entryPath || path].tree.forEach(f =>
dispatch('renameEntry', { path, name, entryPath: f.path }),
);
if (!entryPath) {
dispatch('deleteEntry', path);
}
}; };
export * from './actions/tree'; export * from './actions/tree';
......
...@@ -201,27 +201,35 @@ export default { ...@@ -201,27 +201,35 @@ export default {
state.changedFiles = state.changedFiles.concat(entry); state.changedFiles = state.changedFiles.concat(entry);
parent.tree = parent.tree.filter(f => f.path !== entry.path); parent.tree = parent.tree.filter(f => f.path !== entry.path);
}, },
[types.RENAME_ENTRY](state, { path, name }) { [types.RENAME_ENTRY](state, { path, name, entryPath = null }) {
const oldEntry = state.entries[path]; const oldEntry = state.entries[entryPath || path];
const parent = oldEntry.parentPath const nameRegex = new RegExp(`^${path}`);
? state.entries[oldEntry.parentPath] const newPath = oldEntry.path.replace(nameRegex, name);
: state.trees[`${state.currentProjectId}/${state.currentBranchId}`]; const parentPath = oldEntry.parentPath ? oldEntry.parentPath.replace(nameRegex, name) : '';
const nameRegex = new RegExp(`${oldEntry.name}$`);
const newPath = path.replace(nameRegex, name);
state.entries[newPath] = { state.entries[newPath] = {
...oldEntry, ...oldEntry,
id: newPath, id: newPath,
key: `${name}-${oldEntry.type}-${oldEntry.id}`, key: `${name}-${oldEntry.type}-${oldEntry.id}`,
path: newPath, path: newPath,
name, name: entryPath ? oldEntry.name : name,
tempFile: true, tempFile: true,
prevPath: path, prevPath: oldEntry.path,
url: oldEntry.url.replace(nameRegex, name), url: oldEntry.url.replace(new RegExp(`${oldEntry.path}/?$`), newPath),
tree: [],
parentPath,
}; };
oldEntry.moved = true; oldEntry.moved = true;
parent.tree = parent.tree.concat(state.entries[newPath]);
state.changedFiles = state.changedFiles.concat(state.entries[newPath]); const parent = parentPath
? state.entries[parentPath]
: state.trees[`${state.currentProjectId}/${state.currentBranchId}`];
parent.tree = sortTree(parent.tree.concat(state.entries[newPath]));
if (!entryPath) {
state.changedFiles = state.changedFiles.concat(state.entries[newPath]);
}
}, },
...projectMutations, ...projectMutations,
...mergeRequestMutation, ...mergeRequestMutation,
......
...@@ -124,7 +124,7 @@ export const getCommitFiles = (stagedFiles, deleteTree = false) => ...@@ -124,7 +124,7 @@ export const getCommitFiles = (stagedFiles, deleteTree = false) =>
stagedFiles.reduce((acc, file) => { stagedFiles.reduce((acc, file) => {
if (file.moved) return acc; if (file.moved) return acc;
if ((file.deleted || deleteTree) && file.type === 'tree') { if ((file.deleted || deleteTree || file.prevPath) && file.type === 'tree') {
return acc.concat(getCommitFiles(file.tree, true)); return acc.concat(getCommitFiles(file.tree, true));
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment