Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent no branches #1074

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
# build artifacts
mergerfs
obj/
*.d
build/
src/version.hpp

# Debian files
Expand All @@ -23,3 +25,7 @@ debian/changelog

# RPM files
rpmbuild/

# IDEs
\.idea/
VERSION
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,10 @@ LDFLAGS := \
-pthread \
-lrt

ifeq ($(DEBUG),1)
LDFLAGS := ${LDFLAGS} -fsanitize=undefined
endif

DESTDIR =
PREFIX = /usr/local
EXEC_PREFIX = $(PREFIX)
Expand Down
16 changes: 12 additions & 4 deletions src/branches.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,8 @@ namespace l
uint64_t offset;

offset = s_.find_first_not_of("+<>-=");
if(offset > 1)
offset = 2;
*values_ = ((offset != std::string::npos) ? s_.substr(offset) : "");
*instr_ = s_.substr(0,offset);
if(offset != std::string::npos)
*values_ = s_.substr(offset);
}

static
Expand Down Expand Up @@ -205,6 +202,9 @@ namespace l
Branches::Impl tmp_branches(branches_->minfreespace());

str::split(str_,':',&paths);
if (paths.empty())
return -ENOTSUP;

for(auto &path : paths)
{
rv = l::parse(path,&tmp_branches);
Expand Down Expand Up @@ -269,6 +269,9 @@ namespace l
int
erase_begin(Branches::Impl *branches_)
{
if (branches_->size() <= 1)
return -ENOTSUP;

branches_->erase(branches_->begin());

return 0;
Expand All @@ -278,6 +281,9 @@ namespace l
int
erase_end(Branches::Impl *branches_)
{
if (branches_->size() <= 1)
return -ENOTSUP;

branches_->pop_back();

return 0;
Expand All @@ -299,6 +305,8 @@ namespace l
{
match = ::fnmatch(pi->c_str(),i->path.c_str(),0);
}
if (match == 0 && branches_->size() == 1)
return -ENOTSUP;

i = ((match == 0) ? branches_->erase(i) : (i+1));
}
Expand Down
62 changes: 62 additions & 0 deletions tests/tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,67 @@ test_config_branches()
TEST_CHECK(b.from_string("./foo/bar:/bar/baz:blah/asdf") == 0);
}


void
test_config_update_branches()
{
uint64_t minfreespace;
Branches b(minfreespace);

minfreespace = 1234;

//
TEST_CHECK(b.from_string("/first:/second") == 0);

TEST_CHECK(b.from_string("-/first") == 0);
TEST_CHECK(b.to_string() == "/second=RW");

TEST_CHECK(b.from_string("+>/last") == 0);
TEST_CHECK(b.to_string() == "/second=RW:/last=RW");

TEST_CHECK(b.from_string("+/last") == 0);
TEST_CHECK(b.to_string() == "/second=RW:/last=RW:/last=RW");

//
TEST_CHECK(b.from_string("/second") == 0);

TEST_CHECK(b.from_string("+</first") == 0);
TEST_CHECK(b.to_string() == "/first=RW:/second=RW");

//
TEST_CHECK(b.from_string("/first:/second") == 0);
TEST_CHECK(b.from_string("-/second") == 0);
TEST_CHECK(b.to_string() == "/first=RW");

//
TEST_CHECK(b.from_string("/first:/second") == 0);

TEST_CHECK(b.from_string("->") == 0);
TEST_CHECK(b.to_string() == "/first=RW");

//
TEST_CHECK(b.from_string("/first:/second") == 0);

TEST_CHECK(b.from_string("-<") == 0);
TEST_CHECK(b.to_string() == "/second=RW");

//
TEST_CHECK(b.from_string("=/dir") == 0);
TEST_CHECK(b.to_string() == "/dir=RW");
TEST_CHECK(b.from_string("/dir") == 0);
TEST_CHECK(b.to_string() == "/dir=RW");

// error out when no branches left
TEST_CHECK(b.from_string("=/dir") == 0);
TEST_CHECK(b.from_string("-/dir") < 0);
TEST_CHECK(b.from_string("-<") < 0);
TEST_CHECK(b.from_string("->") < 0);

// error out when setting empty branches
TEST_CHECK(b.from_string("=") < 0);
TEST_CHECK(b.from_string("") < 0);
}

void
test_config_cachefiles()
{
Expand Down Expand Up @@ -274,6 +335,7 @@ TEST_LIST =
{"config_int",test_config_int},
{"config_str",test_config_str},
{"config_branches",test_config_branches},
{"config_update_branches",test_config_update_branches},
{"config_cachefiles",test_config_cachefiles},
{"config_inodecalc",test_config_inodecalc},
{"config_moveonenospc",test_config_moveonenospc},
Expand Down
4 changes: 2 additions & 2 deletions tools/git2debcl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/env python3

# Copyright (c) 2016, Antonio SJ Musumeci <[email protected]>

Expand All @@ -19,7 +19,7 @@ import subprocess
import argparse

def call(args):
return subprocess.Popen(args,stdout=subprocess.PIPE).communicate()[0].decode()
return subprocess.Popen(args,stdout=subprocess.PIPE).communicate()[0].decode('utf-8')

def git_tags():
args = ["git", "tag", '-l']
Expand Down