chiark / gitweb /
Test suite: tartree-edit: gitfetchinfo: Unmerge merged refs
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Sat, 2 Jul 2016 10:25:54 +0000 (11:25 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Sat, 2 Jul 2016 10:35:31 +0000 (11:35 +0100)
The sequence
  gitfetchinfo-merge A B
  gitfetchinfo A
  gitfetchinfo-merge A B
might leave inappropriate A+B refs, because nothing would delete them.

So, have gitfetchinfo A unmerge any A+B or B+A refs.  (This does mean
that the user of gitfetchinfo A is now promising that any remotes A+B
or B+A were made with gitfetchinfo-merge.)

tests/tartree-edit

index 1aeab3d..cecc142 100755 (executable)
@@ -116,6 +116,7 @@ gitfetchinfo_perhaps_commit () {
 
 tryat_gitfetchinfo () {
        git_manip_play
+
        if test -d "$b.edit"; then
                cp -a "$b.edit"/. "$play"/.
        else
@@ -123,7 +124,24 @@ tryat_gitfetchinfo () {
                tar -C $play -f - <&3 -x
                exec 3<&-
        fi
-       local innerwd=$play/*
+
+       local innerwd="$(echo $play/*)"
+
+       git for-each-ref --format='%(refname)' refs/remotes >$play/l
+       perl -ne '
+           chomp;
+           next unless m#^refs/remotes/([^/]+)/#;
+           my $old = $_;
+           my $ab = $1;
+           my $rhs = $'\'';
+           my @ab = split /\+/, $ab;
+           next unless @ab == 2;
+           next unless grep { $_ eq "'"$remote"'" } @ab;
+           print "update refs/remotes/$_/$rhs $old\n" or die $! foreach @ab;
+           print "delete $old\n" or die $!;
+       ' <$play/l >$play/unmerge
+       git update-ref --stdin <$play/unmerge
+
        git remote remove "$remote" 2>/dev/null ||:
        git remote add "$remote" $innerwd
        git fetch --no-tags -p "$remote" \