Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
ab72cfc3
Commit
ab72cfc3
authored
Dec 21, 2019
by
GitLab Bot
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add latest changes from gitlab-org/gitlab@master
parent
483a66c0
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
52 additions
and
34 deletions
+52
-34
app/assets/javascripts/ide/stores/actions/file.js
app/assets/javascripts/ide/stores/actions/file.js
+24
-15
changelogs/unreleased/27244-discard-fix.yml
changelogs/unreleased/27244-discard-fix.yml
+5
-0
spec/frontend/ide/stores/actions/file_spec.js
spec/frontend/ide/stores/actions/file_spec.js
+23
-19
No files found.
app/assets/javascripts/ide/stores/actions/file.js
View file @
ab72cfc3
...
...
@@ -191,25 +191,34 @@ export const discardFileChanges = ({ dispatch, state, commit, getters }, path) =
dispatch
(
'
restoreTree
'
,
file
.
parentPath
);
}
commit
(
types
.
DISCARD_FILE_CHANGES
,
path
);
commit
(
types
.
REMOVE_FILE_FROM_CHANGED
,
path
);
if
(
file
.
prevPath
)
{
dispatch
(
'
discardFileChanges
'
,
file
.
prevPath
);
}
if
(
file
.
tempFile
||
file
.
prevPath
)
{
dispatch
(
'
closeFile
'
,
file
);
if
(
file
.
tempFile
&&
file
.
opened
)
{
commit
(
types
.
TOGGLE_FILE_OPEN
,
path
);
}
else
if
(
getters
.
activeFile
&&
file
.
path
===
getters
.
activeFile
.
path
)
{
dispatch
(
'
updateDelayViewerUpdated
'
,
true
)
.
then
(()
=>
{
router
.
push
(
`/project
${
file
.
url
}
`
);
})
.
catch
(
e
=>
{
throw
e
;
if
(
file
.
tempFile
)
{
dispatch
(
'
deleteEntry
'
,
file
.
path
);
}
else
{
dispatch
(
'
renameEntry
'
,
{
path
:
file
.
path
,
name
:
file
.
prevName
,
parentPath
:
file
.
prevParentPath
,
});
}
}
else
{
commit
(
types
.
DISCARD_FILE_CHANGES
,
path
);
if
(
getters
.
activeFile
&&
file
.
path
===
getters
.
activeFile
.
path
)
{
dispatch
(
'
updateDelayViewerUpdated
'
,
true
)
.
then
(()
=>
{
router
.
push
(
`/project
${
file
.
url
}
`
);
})
.
catch
(
e
=>
{
throw
e
;
});
}
}
commit
(
types
.
REMOVE_FILE_FROM_CHANGED
,
path
);
eventHub
.
$emit
(
`editor.update.model.new.content.
${
file
.
key
}
`
,
file
.
content
);
eventHub
.
$emit
(
`editor.update.model.dispose.unstaged-
${
file
.
key
}
`
,
file
.
content
);
};
...
...
changelogs/unreleased/27244-discard-fix.yml
0 → 100644
View file @
ab72cfc3
---
title
:
Fix "Discard" for newly-created and renamed files
merge_request
:
21905
author
:
type
:
fixed
spec/frontend/ide/stores/actions/file_spec.js
View file @
ab72cfc3
...
...
@@ -581,11 +581,13 @@ describe('IDE store file actions', () => {
jest
.
spyOn
(
eventHub
,
'
$on
'
).
mockImplementation
(()
=>
{});
jest
.
spyOn
(
eventHub
,
'
$emit
'
).
mockImplementation
(()
=>
{});
tmpFile
=
file
();
tmpFile
=
file
(
'
tempFile
'
);
tmpFile
.
content
=
'
testing
'
;
store
.
state
.
changedFiles
.
push
(
tmpFile
);
store
.
state
.
entries
[
tmpFile
.
path
]
=
tmpFile
;
jest
.
spyOn
(
store
,
'
dispatch
'
);
});
it
(
'
resets file content
'
,
done
=>
{
...
...
@@ -610,33 +612,35 @@ describe('IDE store file actions', () => {
.
catch
(
done
.
fail
);
});
it
(
'
closes temp file
'
,
done
=>
{
it
(
'
closes temp file
and deletes it
'
,
()
=>
{
tmpFile
.
tempFile
=
true
;
tmpFile
.
opened
=
true
;
tmpFile
.
parentPath
=
'
parentFile
'
;
store
.
state
.
entries
.
parentFile
=
file
(
'
parentFile
'
);
store
.
dispatch
(
'
discardFileChanges
'
,
tmpFile
.
path
)
.
then
(()
=>
{
expect
(
tmpFile
.
opened
).
toBeFalsy
();
actions
.
discardFileChanges
(
store
,
tmpFile
.
path
);
done
();
})
.
catch
(
done
.
fail
);
expect
(
store
.
dispatch
).
toHaveBeenCalledWith
(
'
closeFile
'
,
tmpFile
);
expect
(
store
.
dispatch
).
toHaveBeenCalledWith
(
'
deleteEntry
'
,
tmpFile
.
path
);
});
it
(
'
does not re-open a closed temp file
'
,
done
=>
{
tmpFile
.
tempFile
=
true
;
it
(
'
renames the file to its original name and closes it if it was open
'
,
()
=>
{
Object
.
assign
(
tmpFile
,
{
prevPath
:
'
parentPath/old_name
'
,
prevName
:
'
old_name
'
,
prevParentPath
:
'
parentPath
'
,
});
expect
(
tmpFile
.
opened
).
toBeFalsy
(
);
store
.
state
.
entries
.
parentPath
=
file
(
'
parentPath
'
);
store
.
dispatch
(
'
discardFileChanges
'
,
tmpFile
.
path
)
.
then
(()
=>
{
expect
(
tmpFile
.
opened
).
toBeFalsy
();
actions
.
discardFileChanges
(
store
,
tmpFile
.
path
);
done
();
})
.
catch
(
done
.
fail
);
expect
(
store
.
dispatch
).
toHaveBeenCalledWith
(
'
closeFile
'
,
tmpFile
);
expect
(
store
.
dispatch
).
toHaveBeenCalledWith
(
'
renameEntry
'
,
{
path
:
'
tempFile
'
,
name
:
'
old_name
'
,
parentPath
:
'
parentPath
'
,
});
});
it
(
'
pushes route for active file
'
,
done
=>
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment