summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/ide/stores/utils.js
diff options
context:
space:
mode:
Diffstat (limited to 'app/assets/javascripts/ide/stores/utils.js')
-rw-r--r--app/assets/javascripts/ide/stores/utils.js24
1 files changed, 13 insertions, 11 deletions
diff --git a/app/assets/javascripts/ide/stores/utils.js b/app/assets/javascripts/ide/stores/utils.js
index bf7ab93ff5e..0ede76fd1e0 100644
--- a/app/assets/javascripts/ide/stores/utils.js
+++ b/app/assets/javascripts/ide/stores/utils.js
@@ -47,6 +47,9 @@ export const dataStructure = () => ({
lastOpenedAt: 0,
mrChange: null,
deleted: false,
+ prevPath: '',
+ movedPath: '',
+ moved: false,
});
export const decorateData = entity => {
@@ -107,7 +110,9 @@ export const setPageTitle = title => {
};
export const commitActionForFile = file => {
- if (file.deleted) {
+ if (file.prevPath) {
+ return 'move';
+ } else if (file.deleted) {
return 'delete';
} else if (file.tempFile) {
return 'create';
@@ -116,15 +121,12 @@ export const commitActionForFile = file => {
return 'update';
};
-export const getCommitFiles = (stagedFiles, deleteTree = false) =>
+export const getCommitFiles = stagedFiles =>
stagedFiles.reduce((acc, file) => {
- if ((file.deleted || deleteTree) && file.type === 'tree') {
- return acc.concat(getCommitFiles(file.tree, true));
- }
+ if (file.moved) return acc;
return acc.concat({
...file,
- deleted: deleteTree || file.deleted,
});
}, []);
@@ -134,9 +136,10 @@ export const createCommitPayload = ({ branch, getters, newBranch, state, rootSta
actions: getCommitFiles(rootState.stagedFiles).map(f => ({
action: commitActionForFile(f),
file_path: f.path,
- content: f.content,
+ previous_path: f.prevPath === '' ? undefined : f.prevPath,
+ content: f.content || undefined,
encoding: f.base64 ? 'base64' : 'text',
- last_commit_id: newBranch || f.deleted ? undefined : f.lastCommitSha,
+ last_commit_id: newBranch || f.deleted || f.prevPath ? undefined : f.lastCommitSha,
})),
start_branch: newBranch ? rootState.currentBranchId : undefined,
});
@@ -164,8 +167,7 @@ export const sortTree = sortedTree =>
)
.sort(sortTreesByTypeAndName);
-export const filePathMatches = (f, path) =>
- f.path.replace(new RegExp(`${f.name}$`), '').indexOf(`${path}/`) === 0;
+export const filePathMatches = (filePath, path) => filePath.indexOf(`${path}/`) === 0;
export const getChangesCountForFiles = (files, path) =>
- files.filter(f => filePathMatches(f, path)).length;
+ files.filter(f => filePathMatches(f.path, path)).length;