aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--SBO-Lib/lib/SBO/Lib.pm6
-rwxr-xr-xt/11-git.t86
2 files changed, 89 insertions, 3 deletions
diff --git a/SBO-Lib/lib/SBO/Lib.pm b/SBO-Lib/lib/SBO/Lib.pm
index 066dc12..e50c04c 100644
--- a/SBO-Lib/lib/SBO/Lib.pm
+++ b/SBO-Lib/lib/SBO/Lib.pm
@@ -299,9 +299,9 @@ sub git_sbo_tree {
if (-d "$repo_path/.git" and check_git_remote($repo_path, $url)) {
my $cwd = getcwd();
chdir $repo_path;
- system(qw/ git reset HEAD --hard /) == 0 or chdir $cwd and return 0;
- system(qw/ git fetch /) == 0 or chdir $cwd and return 0;
- system(qw/ git pull /) == 0 or chdir $cwd and return 0;
+ system(qw! git fetch !) == 0 or chdir $cwd and return 0;
+ system(qw! git reset --hard origin !) == 0 or chdir $cwd and return 0;
+ unlink "$repo_path/SLACKBUILDS.TXT";
chdir $cwd and return 1;
} else {
my $cwd = getcwd();
diff --git a/t/11-git.t b/t/11-git.t
new file mode 100755
index 0000000..00f4299
--- /dev/null
+++ b/t/11-git.t
@@ -0,0 +1,86 @@
+#!/usr/bin/env perl
+
+use 5.16.0;
+use strict;
+use warnings FATAL => 'all';
+use Test::More;
+use Capture::Tiny qw/ capture_merged /;
+use FindBin '$RealBin';
+use lib $RealBin;
+use lib "$RealBin/../SBO-Lib/lib";
+use Test::Execute;
+
+if ($ENV{TEST_INSTALL}) {
+ plan tests => 3;
+} else {
+ plan skip_all => 'Only run these tests if TEST_INSTALL=1';
+}
+
+$path = "$RealBin/../";
+
+sub cleanup {
+ capture_merged {
+ system(qw!rm -rf !, "$RealBin/gitrepo");
+ };
+}
+
+sub set_repo {
+ state $set = 0;
+ state $orig;
+ if ($_[0]) {
+ if ($set) {
+ capture_merged { system(qw!rm -rf /usr/sbo/repo!); system('mv', "$RealBin/repo.backup", "/usr/sbo/repo"); } if -e "$RealBin/repo.backup";
+ script (qw/ sboconfig -r /, $orig, { test => 0 });
+ }
+ } else {
+ ($orig) = script (qw/ sboconfig -l /, { expected => qr/REPO=(.*)/, test => 0 });
+ $orig //= 'FALSE';
+ note "Saving original value of REPO: $orig";
+ $set = 1;
+ script (qw/ sboconfig -r /, "file://$RealBin/gitrepo/", { test => 0 });
+ capture_merged { system(qw! mv /usr/sbo/repo !, "$RealBin/repo.backup"); } if -e "/usr/sbo/repo";
+ }
+}
+
+sub slurp {
+ my $file = shift;
+ local $/;
+ open my $fh, '<', $file or return undef;
+ my $contents = <$fh>;
+ return $contents;
+}
+
+cleanup();
+
+# initialise repo
+capture_merged { system(<<"END"); };
+cd $RealBin; rm -rf gitrepo; mkdir gitrepo; cd gitrepo;
+git init;
+echo "echo Hello" > test; git add test; git commit -m 'initial';
+git checkout -b b1; echo 'echo "Hello World."' > test; git commit -am 'branch commit';
+git checkout master; echo 'echo "Hello World"' > test; git commit -am 'master commit';
+END
+
+set_repo();
+
+# 1: sbosnap get initial repo
+script (qw/ sbosnap fetch /, { expected => qr!Pulling SlackBuilds tree.*Cloning into '/usr/sbo/repo'!s });
+
+# make a conflict
+capture_merged { system(<<"END"); };
+cd $RealBin; cd gitrepo; git reset --hard b1
+END
+
+# 2: sbosnap update through merge conflict
+script (qw/ sbosnap update /, { expected => qr!Updating SlackBuilds tree.*master.*->.*origin/master.*forced update.*HEAD is now at!s });
+
+# 3: make sure test repo is merged correctly
+is (slurp('/usr/sbo/repo/test'), <<"END", 'repo test file updated correctly');
+echo "Hello World."
+END
+
+# Cleanup
+END {
+ set_repo('delete');
+ cleanup();
+}