mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-06-26 10:54:26 +02:00
Merge command
- improved merge.autopush=ask - fixed newline issues - fixed: entries for new tasks got lost in undo.data
This commit is contained in:
parent
5c36013ddd
commit
b041e54be6
3 changed files with 39 additions and 20 deletions
14
src/TDB.cpp
14
src/TDB.cpp
|
@ -1141,7 +1141,7 @@ void TDB::merge (const std::string& mergeFile)
|
|||
lline = *lit;
|
||||
|
||||
// push the line to the new undo.data
|
||||
undo.push_back (lline);
|
||||
undo.push_back (lline + "\n");
|
||||
|
||||
// found first matching lines?
|
||||
if (lline.compare (rline) == 0)
|
||||
|
@ -1389,7 +1389,8 @@ void TDB::merge (const std::string& mergeFile)
|
|||
|
||||
// iterate over taskmod list
|
||||
std::list<Taskmod>::iterator it;
|
||||
for (it = mods.begin (); it != mods.end (); ) {
|
||||
for (it = mods.begin (); it != mods.end (); )
|
||||
{
|
||||
std::list<Taskmod>::iterator current = it++;
|
||||
Taskmod tmod = *current;
|
||||
|
||||
|
@ -1507,13 +1508,18 @@ void TDB::merge (const std::string& mergeFile)
|
|||
if (!found)
|
||||
{
|
||||
std::cout << "Adding " << uuid << "\n";
|
||||
pending.push_back (tmod.getAfter ().composeF4 ());
|
||||
// remove the \n from composeF4() string
|
||||
std::string newline = tmod.getAfter ().composeF4 ();
|
||||
newline = newline.substr (0, newline.length ()-1);
|
||||
pending.push_back (newline);
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cout << "Not adding duplicate " << uuid << "\n";
|
||||
mods.erase (current);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// write pending file
|
||||
if (! File::write (pendingFile, pending))
|
||||
|
@ -1535,7 +1541,7 @@ void TDB::merge (const std::string& mergeFile)
|
|||
}
|
||||
|
||||
// write undo file
|
||||
if (! File::write (undoFile, undo, true))
|
||||
if (! File::write (undoFile, undo, false))
|
||||
throw std::string ("Could not write '") + undoFile + "'.";
|
||||
}
|
||||
else // nothing to be done
|
||||
|
|
|
@ -583,18 +583,28 @@ void handleMerge (std::string& outs)
|
|||
if (context.hooks.trigger ("pre-merge-command"))
|
||||
{
|
||||
std::string file = trim (context.task.get ("description"));
|
||||
std::string pushfile = "";
|
||||
std::string tmpfile = "";
|
||||
|
||||
std::string sAutopush = context.config.get ("merge.autopush");
|
||||
bool bAutopush = context.config.getBoolean("merge.autopush");
|
||||
|
||||
if (file.length () == 0)
|
||||
{
|
||||
// get default target from config
|
||||
file = context.config.get ("merge.default.uri");
|
||||
|
||||
if (sAutopush == "ask")
|
||||
pushfile = context.config.get ("push.default.uri");
|
||||
}
|
||||
else
|
||||
{
|
||||
// replace argument with uri from config
|
||||
std::string tmp = context.config.get ("merge." + file + ".uri");
|
||||
|
||||
if (sAutopush == "ask")
|
||||
pushfile = context.config.get ("push." + file + ".uri");
|
||||
|
||||
if (tmp != "")
|
||||
file = tmp;
|
||||
}
|
||||
|
@ -631,20 +641,17 @@ void handleMerge (std::string& outs)
|
|||
if (tmpfile != "")
|
||||
{
|
||||
remove (tmpfile.c_str());
|
||||
}
|
||||
|
||||
std::string autopush = context.config.get ("merge.autopush");
|
||||
|
||||
// TODO Task accepts many different values for "yes". Try Config::getBoolean.
|
||||
if ( ((autopush == "ask") && (confirm ("Do you want to push the changes to the database you merged from?")) )
|
||||
|| (autopush == "yes") )
|
||||
if ( ((sAutopush == "ask") && (confirm ("Do you want to push the changes to \'" + pushfile + "\'?")) )
|
||||
|| (bAutopush) )
|
||||
{
|
||||
std::string out;
|
||||
handlePush(out);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
else // TODO : get default source from config file
|
||||
else
|
||||
throw std::string ("You must specify a file to merge.");
|
||||
}
|
||||
}
|
||||
|
@ -663,7 +670,7 @@ void handlePush (std::string& outs)
|
|||
}
|
||||
else
|
||||
{
|
||||
// replace argument with uri from config
|
||||
// try to replace argument with uri from config
|
||||
std::string tmp = context.config.get ("push." + file + ".uri");
|
||||
|
||||
if (tmp != "")
|
||||
|
@ -682,12 +689,16 @@ void handlePush (std::string& outs)
|
|||
}
|
||||
else
|
||||
{
|
||||
throw std::string ("Push failed");
|
||||
// TODO copy files
|
||||
//std::ifstream ifile (location.data + "/undo.data", std::ios_base::binary);
|
||||
//std::ofstream ofile (location.data + "/undo.data", std::ios_base::binary);
|
||||
|
||||
throw std::string ("Push to local targets is not (yet) supported.");
|
||||
}
|
||||
|
||||
context.hooks.trigger ("post-push-command");
|
||||
}
|
||||
else // TODO : get default target from config file
|
||||
else
|
||||
throw std::string ("You must specify a target.");
|
||||
}
|
||||
}
|
||||
|
@ -739,7 +750,7 @@ void handlePull (std::string& outs)
|
|||
|
||||
context.hooks.trigger ("post-pull-command");
|
||||
}
|
||||
else // TODO : get default target from config file
|
||||
else
|
||||
throw std::string ("You must specify a target.");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -136,7 +136,9 @@ sleep(1);
|
|||
qx{../task rc:remote.rc 4 +gym}; # right_newer
|
||||
|
||||
# merge remote into local
|
||||
copy("local/undo.data", "local/undo.save") or fail("copy local/undo.data to local/undo.save");
|
||||
my $output_l = qx{../task rc:local.rc merge remote/undo.data};
|
||||
rename("local/undo.save", "local/undo.data") or fail("rename local/undo.save in local/undo.data");
|
||||
|
||||
#check output
|
||||
like ($output_l, qr/Running redo/, "local-merge finished");
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue