• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

GothenburgBitFactory / taskwarrior / 10152339701

29 Jul 2024 09:45PM UTC coverage: 84.437% (+0.07%) from 84.372%
10152339701

push

github

web-flow
Merge pull request #3566 from felixschurk/add-clang-format

Add clang-format to enforce style guide

12359 of 13760 new or added lines in 147 files covered. (89.82%)

123 existing lines in 42 files now uncovered.

19070 of 22585 relevant lines covered (84.44%)

19724.02 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

67.86
/src/commands/CmdSync.cpp
1
////////////////////////////////////////////////////////////////////////////////
2
//
3
// Copyright 2006 - 2021, Tomas Babej, Paul Beckingham, Federico Hernandez.
4
//
5
// Permission is hereby granted, free of charge, to any person obtaining a copy
6
// of this software and associated documentation files (the "Software"), to deal
7
// in the Software without restriction, including without limitation the rights
8
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
// copies of the Software, and to permit persons to whom the Software is
10
// furnished to do so, subject to the following conditions:
11
//
12
// The above copyright notice and this permission notice shall be included
13
// in all copies or substantial portions of the Software.
14
//
15
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
16
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
// SOFTWARE.
22
//
23
// https://www.opensource.org/licenses/mit-license.php
24
//
25
////////////////////////////////////////////////////////////////////////////////
26

27
#include <cmake.h>
28
// cmake.h include header must come first
29

30
#include <CmdSync.h>
31
#include <Color.h>
32
#include <Context.h>
33
#include <Filter.h>
34
#include <format.h>
35
#include <inttypes.h>
36
#include <shared.h>
37
#include <signal.h>
38
#include <util.h>
39

40
#include <sstream>
41

42
#include "tc/Server.h"
43

44
////////////////////////////////////////////////////////////////////////////////
45
CmdSync::CmdSync() {
4,389✔
46
  _keyword = "synchronize";
4,389✔
47
  _usage = "task          synchronize [initialize]";
4,389✔
48
  _description = "Synchronizes data with the Taskserver";
4,389✔
49
  _read_only = false;
4,389✔
50
  _displays_id = false;
4,389✔
51
  _needs_gc = false;
4,389✔
52
  _uses_context = false;
4,389✔
53
  _accepts_filter = false;
4,389✔
54
  _accepts_modifications = false;
4,389✔
55
  _accepts_miscellaneous = true;
4,389✔
56
  _category = Command::Category::migration;
4,389✔
57
}
4,389✔
58

59
////////////////////////////////////////////////////////////////////////////////
60
int CmdSync::execute(std::string& output) {
2✔
61
  int status = 0;
2✔
62

63
  tc::Server server;
2✔
64
  std::string server_ident;
2✔
65

66
  // If no server is set up, quit.
67
  std::string origin = Context::getContext().config.get("sync.server.origin");
4✔
68
  std::string url = Context::getContext().config.get("sync.server.url");
4✔
69
  std::string server_dir = Context::getContext().config.get("sync.local.server_dir");
4✔
70
  std::string gcp_credential_path = Context::getContext().config.get("sync.gcp.credential_path");
4✔
71
  std::string gcp_bucket = Context::getContext().config.get("sync.gcp.bucket");
4✔
72
  std::string encryption_secret = Context::getContext().config.get("sync.encryption_secret");
4✔
73

74
  // sync.server.origin is a deprecated synonym for sync.server.url
75
  std::string server_url = url == "" ? origin : url;
2✔
76

77
  if (server_dir != "") {
2✔
78
    server = tc::Server::new_local(server_dir);
2✔
79
    server_ident = server_dir;
2✔
80
  } else if (gcp_bucket != "") {
×
81
    if (encryption_secret == "") {
×
NEW
82
      throw std::string("sync.encryption_secret is required");
×
83
    }
NEW
84
    server = tc::Server::new_gcp(gcp_bucket, gcp_credential_path, encryption_secret);
×
85
    std::ostringstream os;
×
86
    os << "GCP bucket " << gcp_bucket;
×
87
    server_ident = os.str();
×
88
  } else if (server_url != "") {
×
NEW
89
    std::string client_id = Context::getContext().config.get("sync.server.client_id");
×
90
    if (client_id == "" || encryption_secret == "") {
×
NEW
91
      throw std::string("sync.server.client_id and sync.encryption_secret are required");
×
92
    }
NEW
93
    server = tc::Server::new_sync(server_url, client_id, encryption_secret);
×
94
    std::ostringstream os;
×
95
    os << "Sync server at " << server_url;
×
96
    server_ident = os.str();
×
97
  } else {
×
NEW
98
    throw std::string("No sync.* settings are configured. See task-sync(5).");
×
99
  }
100

101
  std::stringstream out;
2✔
102
  if (origin != "") {
2✔
103
    out << "sync.server.origin is deprecated. Use sync.server.url instead.\n";
×
104
  }
105

106
  if (Context::getContext().verbose("sync")) {
2✔
107
    out << format("Syncing with {1}", server_ident) << '\n';
2✔
108
  }
109

110
  Context& context = Context::getContext();
2✔
111
  context.tdb2.sync(std::move(server), false);
2✔
112

113
  if (context.config.getBoolean("purge.on-sync")) {
2✔
114
    context.tdb2.expire_tasks();
1✔
115
  }
116

117
  output = out.str();
2✔
118
  return status;
2✔
119
}
2✔
120

121
////////////////////////////////////////////////////////////////////////////////
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc