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

fixed folders not being renamed

parent e7fe50bf
......@@ -193,7 +193,7 @@ export default {
data-container="body"
data-placement="right"
name="file-modified"
css-classes="prepend-left-5 multi-file-modified"
css-classes="prepend-left-5 ide-file-modified"
/>
</span>
<changed-file-icon
......
......@@ -193,9 +193,16 @@ export const deleteEntry = ({ commit, dispatch, state }, path) => {
export const resetOpenFiles = ({ commit }) => commit(types.RESET_OPEN_FILES);
export const renameEntry = ({ dispatch, commit }, { path, name }) => {
commit(types.RENAME_ENTRY, { path, name });
dispatch('deleteEntry', path);
export const renameEntry = ({ dispatch, commit, state }, { path, name, entryPath = null }) => {
commit(types.RENAME_ENTRY, { path, name, entryPath });
state.entries[entryPath || path].tree.forEach(f =>
dispatch('renameEntry', { path, name, entryPath: f.path }),
);
if (!entryPath) {
dispatch('deleteEntry', path);
}
};
export * from './actions/tree';
......
......@@ -201,27 +201,35 @@ export default {
state.changedFiles = state.changedFiles.concat(entry);
parent.tree = parent.tree.filter(f => f.path !== entry.path);
},
[types.RENAME_ENTRY](state, { path, name }) {
const oldEntry = state.entries[path];
const parent = oldEntry.parentPath
? state.entries[oldEntry.parentPath]
: state.trees[`${state.currentProjectId}/${state.currentBranchId}`];
const nameRegex = new RegExp(`${oldEntry.name}$`);
const newPath = path.replace(nameRegex, name);
[types.RENAME_ENTRY](state, { path, name, entryPath = null }) {
const oldEntry = state.entries[entryPath || path];
const nameRegex = 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,
name: entryPath ? oldEntry.name : name,
tempFile: true,
prevPath: path,
url: oldEntry.url.replace(nameRegex, name),
prevPath: oldEntry.path,
url: oldEntry.url.replace(new RegExp(`${oldEntry.path}/?$`), newPath),
tree: [],
parentPath,
};
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,
...mergeRequestMutation,
......
......@@ -124,7 +124,7 @@ export const getCommitFiles = (stagedFiles, deleteTree = false) =>
stagedFiles.reduce((acc, file) => {
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));
}
......
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