mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-07-07 20:06:36 +02:00
Enhancement
- Importing the same YAML twice now generates an error.
This commit is contained in:
parent
b32d731010
commit
1cc67e9895
6 changed files with 42 additions and 8 deletions
|
@ -41,6 +41,7 @@
|
|||
+ New fish shell tab completion script (thanks to Mick Koch).
|
||||
+ Color rules now obey the rc.search.case.sensitive configuration option.
|
||||
+ The color.keyword.XXX color rule now applies to annotations too.
|
||||
+ Importing the same YAML twice now generates an error.
|
||||
+ Fixed bug #427, preventing the task edit command to parse annotation
|
||||
dates with spaces.
|
||||
+ Fixed bug #433, making task command output more consistent.
|
||||
|
|
3
NEWS
3
NEWS
|
@ -13,7 +13,8 @@ New Features in taskwarrior 1.9.3
|
|||
- Now supports 'now' as a date/time.
|
||||
- Now defines an overdue task as being one second after the due date,
|
||||
instead of the day after the due date.
|
||||
- Import and export of YAML 1.1, including round-trip capability.
|
||||
- Import and export of YAML 1.1, including round-trip capability, and
|
||||
detection of duplicate imports.
|
||||
- New merge capability for syncing task data files.
|
||||
- New push capability for distributing merged changes.
|
||||
- When completing or modifying a task, the project status is displayed.
|
||||
|
|
33
src/TDB.cpp
33
src/TDB.cpp
|
@ -463,17 +463,25 @@ const std::vector <Task>& TDB::getAllModified ()
|
|||
// Note: mLocations[0] is where all tasks are written.
|
||||
void TDB::add (const Task& task)
|
||||
{
|
||||
std::string unique;
|
||||
Task t (task);
|
||||
if (task.get ("uuid") == "")
|
||||
{
|
||||
std::string unique = ::uuid ();
|
||||
t.set ("uuid", unique);
|
||||
}
|
||||
unique = ::uuid ();
|
||||
else
|
||||
t.set ("uuid", task.get ("uuid"));
|
||||
unique = task.get ("uuid");
|
||||
|
||||
t.set ("uuid", unique);
|
||||
|
||||
// If the tasks are loaded, then verify that this uuid is not already in
|
||||
// the file.
|
||||
if (uuidAlreadyUsed (unique, mNew) ||
|
||||
uuidAlreadyUsed (unique, mModified) ||
|
||||
uuidAlreadyUsed (unique, mPending) ||
|
||||
uuidAlreadyUsed (unique, mCompleted))
|
||||
throw std::string ("Cannot add task because the uuid '") + unique + "' is not unique.";
|
||||
|
||||
mNew.push_back (t);
|
||||
mI2U[task.id] = t.get ("uuid");
|
||||
mI2U[task.id] = unique;
|
||||
mU2I[task.get ("uuid")] = t.id;
|
||||
}
|
||||
|
||||
|
@ -1610,3 +1618,16 @@ void TDB::writeUndo (const Task& before, const Task& after, FILE* file)
|
|||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
bool TDB::uuidAlreadyUsed (
|
||||
const std::string& uuid,
|
||||
const std::vector <Task>& all)
|
||||
{
|
||||
std::vector <Task>::const_iterator it;
|
||||
for (it = all.begin (); it != all.end (); ++it)
|
||||
if (it->get ("uuid") == uuid)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
|
|
@ -76,6 +76,8 @@ private:
|
|||
FILE* openAndLock (const std::string&);
|
||||
void writeUndo (const Task&, FILE*);
|
||||
void writeUndo (const Task&, const Task&, FILE*);
|
||||
bool uuidAlreadyUsed (const std::string&);
|
||||
bool uuidAlreadyUsed (const std::string&, const std::vector <Task>&);
|
||||
|
||||
private:
|
||||
std::vector <Location> mLocations;
|
||||
|
|
|
@ -1169,6 +1169,11 @@ static std::string importYAML (const std::vector <std::string>& lines)
|
|||
|
||||
context.tdb.lock (context.config.getBoolean ("locking"));
|
||||
|
||||
// Load all the tasks so that the uuid uniqueness can be checked.
|
||||
std::vector <Task> tasks;
|
||||
Filter filter;
|
||||
context.tdb.load (tasks, filter);
|
||||
|
||||
Task t;
|
||||
|
||||
std::string name;
|
||||
|
|
|
@ -28,7 +28,7 @@
|
|||
|
||||
use strict;
|
||||
use warnings;
|
||||
use Test::More tests => 14;
|
||||
use Test::More tests => 15;
|
||||
|
||||
# Create the rc file.
|
||||
if (open my $fh, '>', 'import.rc')
|
||||
|
@ -96,6 +96,10 @@ unlike ($output, qr/1.+A.+zero/, 't1 missing');
|
|||
unlike ($output, qr/2.+B.+one/, 't2 missing');
|
||||
like ($output, qr/2\/13\/2009.+two/, 't3 present');
|
||||
|
||||
# Make sure that a duplicate task cannot be imported.
|
||||
$output = qx{../task rc:import.rc import import.txt};
|
||||
like ($output, qr/Cannot add task because the uuid .+ is not unique\./, 'error on duplicate uuid');
|
||||
|
||||
# Cleanup.
|
||||
unlink 'import.txt';
|
||||
ok (!-r 'import.txt', 'Removed import.txt');
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue