Compare commits

...

3 Commits

Author SHA1 Message Date
zeripath 5c4075e16d
Fix GetFilesChangedBetween if the file name may be escaped (#23272)
The code for GetFilesChangedBetween uses `git diff --name-only
base..head` to get the names of files changed between base and head
however this forgets that git will escape certain values.

This PR simply switches to use `-z` which has the `NUL` character as the
separator.

Ref https://github.com/go-gitea/gitea/pull/22568#discussion_r1123138096

Signed-off-by: Andrew Thornton <art27@cantab.net>
Co-authored-by: techknowlogick <techknowlogick@gitea.io>
2023-03-03 17:28:38 -05:00
Hester Gong 7f9d58fab8
Support paste treepath when creating a new file or updating the file name (#23209)
Close #23204 

Quick Demo:


https://user-images.githubusercontent.com/17645053/222058727-ad30a37c-f0ac-4184-9946-a71fcee473b5.mov

---------

Co-authored-by: delvh <leon@kske.dev>
2023-03-03 17:28:20 -05:00
ChristianSch 79acf7acc4
Fix grammar in error message (#23273)
Fixes the grammar in the error message in case a runner token has
already been activated
2023-03-03 14:53:46 -06:00
3 changed files with 52 additions and 35 deletions

View File

@ -277,11 +277,18 @@ func (repo *Repository) GetPatch(base, head string, w io.Writer) error {
// GetFilesChangedBetween returns a list of all files that have been changed between the given commits
func (repo *Repository) GetFilesChangedBetween(base, head string) ([]string, error) {
stdout, _, err := NewCommand(repo.Ctx, "diff", "--name-only").AddDynamicArguments(base + ".." + head).RunStdString(&RunOpts{Dir: repo.Path})
stdout, _, err := NewCommand(repo.Ctx, "diff", "--name-only", "-z").AddDynamicArguments(base + ".." + head).RunStdString(&RunOpts{Dir: repo.Path})
if err != nil {
return nil, err
}
return strings.Split(stdout, "\n"), err
split := strings.Split(stdout, "\000")
// Because Git will always emit filenames with a terminal NUL ignore the last entry in the split - which will always be empty.
if len(split) > 0 {
split = split[:len(split)-1]
}
return split, err
}
// GetDiffFromMergeBase generates and return patch data from merge base to head

View File

@ -52,7 +52,7 @@ func (s *Service) Register(
}
if runnerToken.IsActive {
return nil, errors.New("runner token has already activated")
return nil, errors.New("runner token has already been activated")
}
// create new runner

View File

@ -91,36 +91,8 @@ export function initRepoEditor() {
$('#commit-button').text($(this).attr('button_text'));
});
const $editFilename = $('#file-name');
$editFilename.on('keyup', function (e) {
const $section = $('.breadcrumb span.section');
const $divider = $('.breadcrumb div.divider');
let value;
let parts;
if (e.keyCode === 8 && getCursorPosition($(this)) === 0 && $section.length > 0) {
value = $section.last().find('a').text();
$(this).val(value + $(this).val());
$(this)[0].setSelectionRange(value.length, value.length);
$section.last().remove();
$divider.last().remove();
}
if (e.keyCode === 191) {
parts = $(this).val().split('/');
for (let i = 0; i < parts.length; ++i) {
value = parts[i];
if (i < parts.length - 1) {
if (value.length) {
$(`<span class="section"><a href="#">${htmlEscape(value)}</a></span>`).insertBefore($(this));
$('<div class="divider"> / </div>').insertBefore($(this));
}
} else {
$(this).val(value);
}
$(this)[0].setSelectionRange(0, 0);
}
}
parts = [];
const joinTreePath = ($fileNameEl) => {
const parts = [];
$('.breadcrumb span.section').each(function () {
const element = $(this);
if (element.find('a').length) {
@ -129,9 +101,47 @@ export function initRepoEditor() {
parts.push(element.text());
}
});
if ($(this).val()) parts.push($(this).val());
if ($fileNameEl.val()) parts.push($fileNameEl.val());
$('#tree_path').val(parts.join('/'));
}).trigger('keyup');
};
const $editFilename = $('#file-name');
$editFilename.on('input', function () {
const parts = $(this).val().split('/');
if (parts.length > 1) {
for (let i = 0; i < parts.length; ++i) {
const value = parts[i];
if (i < parts.length - 1) {
if (value.length) {
$(`<span class="section"><a href="#">${htmlEscape(value)}</a></span>`).insertBefore($(this));
$('<div class="divider"> / </div>').insertBefore($(this));
}
} else {
$(this).val(value);
}
this.setSelectionRange(0, 0);
}
}
joinTreePath($(this));
});
$editFilename.on('keydown', function (e) {
const $section = $('.breadcrumb span.section');
// Jump back to last directory once the filename is empty
if (e.code === 'Backspace' && getCursorPosition($(this)) === 0 && $section.length > 0) {
e.preventDefault();
const $divider = $('.breadcrumb div.divider');
const value = $section.last().find('a').text();
$(this).val(value + $(this).val());
this.setSelectionRange(value.length, value.length);
$section.last().remove();
$divider.last().remove();
joinTreePath($(this));
}
});
const $editArea = $('.repository.editor textarea#edit_area');
if (!$editArea.length) return;