Thread (1 message) 1 message, 1 author, 2016-06-15
  • (off-list ancestor, not in this archive)
  • Re: conflict status · Junio C Hamano <hidden> · 2016-06-15

Re: conflict status

From: Junio C Hamano <hidden>
Date: 2016-06-15 22:47:09

Michael Wild [off-list ref] writes:
# get all conflicts
conflicts="$(git-status | awk '/unmerged:/{print $3;next}')"

for f in $conflicts; do
  # extract the file mode for base, local and remote
  base_mode=$(git ls-files -u -- "$f" | awk '{if ($3==1) print $1;}')
  local_mode=$(git ls-files -u -- "$f" | awk '{if ($3==2) print $1;}')
  remote_mode=$(git ls-files -u -- "$f" | awk '{if ($3==3) print $1;}')
  # create the status flags
  describe_state "$local_mode"
  describe_state "$remote_mode"
  # append the file name
  echo " $f"
done
Looks an awfully inefficient way to say "git ls-files -u" to me.  If you
do not see stage 2, you do not have it.  If you do not see stage 3, they
do not have it.

If you really really want to condense the object name information out, you
could do something like this.

-- >8 --
#!/bin/sh
git ls-files -u -z |
perl -e '
	$/ = "\0";
        my ($last_path, @stage);
        sub describe_mode {
        	my $ours = $_[0];
		my $sign;
                if (!defined $ours) {
                	$sign = "d";
		} elsif (defined $stage[1]) {
                	$sign = "m";
		} else {
			$sign = "c";
                }
		return $sign;
        }
	sub flush_path {
        	printf("%s %s %s\n",
                	describe_mode($stage[2]),
                	describe_mode($stage[3]),
			$last_path);
		$last_path = undef;
        	@stage = ();
        }
        while (<>) {
		chomp;
        	my ($mode, $sha1, $stage, $path) =
                	/^([0-7]+) ([0-9a-f]{40}) ([1-3])\t(.*)$/;
		if (defined $last_path) {
			flush_path() if ($path ne $last_path);
                }
                $stage[$stage] = 1;
                $last_path = $path;
	}
        if (defined $last_path) {
                flush_path() if ($path ne $last_path);
        }
'
-- 8< --

I however do not think it is all that interesting, though.
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help