From 612c3e10d7d797a48798fa82578760eea2231103 Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Sun, 23 Oct 2016 20:19:50 +0100 Subject: [PATCH] import-dsc: Introduce ff checking Signed-off-by: Ian Jackson --- dgit | 41 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) diff --git a/dgit b/dgit index a1ca0456..ef815997 100755 --- a/dgit +++ b/dgit @@ -5281,7 +5281,11 @@ sub cmd_import_dsc { badusage "dry run makes no sense with import-dsc" unless act_local(); - my $info = "$dscfn"; + my $force = $dstbranch =~ s/^\+// ? +1 : + $dstbranch =~ s/^\.\.// ? -1 : + 0; + my $info = $force ? " $&" : ''; + $info = "$dscfn$info"; my $specbranch = $dstbranch; $dstbranch = "refs/heads/$dstbranch" unless $dstbranch =~ m#^refs/#; @@ -5294,6 +5298,8 @@ sub cmd_import_dsc { fail "$dstbranch is checked out - will not update it" if defined $chead and $chead eq $dstbranch; + my $oldhash = git_get_ref $dstbranch; + open D, "<", $dscfn or fail "open import .dsc ($dscfn): $!"; $dscdata = do { local $/ = undef; ; }; D->error and fail "read $dscfn: $!"; @@ -5315,6 +5321,13 @@ Your git tree does not have that object. Try `git fetch' from a plausible server (browse.dgit.d.o? alioth?), and try the import-dsc again. END } + if ($oldhash && !is_fast_fwd $oldhash, $dgit_commit) { + if ($force > 0) { + progress "Not fast forward, forced update."; + } else { + fail "Not fast forward to $dgit_commit"; + } + } @cmd = (@git, qw(update-ref -m), "dgit import-dsc (Dgit): $info", $dstbranch, $dgit_commit); runcmd @cmd; @@ -5322,6 +5335,13 @@ END return 0; } + fail < 0) { + progress "Import, forced update - synthetic orphan git history."; + } elsif ($force < 0) { + progress "Import, merging."; + my $tree = cmdoutput @git, qw(rev-parse), "$newhash:"; + my $version = getfield $dsc, 'Version'; + $newhash = make_commit_text <