Re: conflict status

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 




On 3. Aug, 2009, at 20:35, Junio C Hamano wrote:

Thomas Rast <trast@xxxxxxxxxxxxxxx> writes:

That only shows 'unmerged: foo' for me...

The closest to porcelain I can get while still having all the
information is

 $ git ls-files -s foo
 100644 e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 1       foo
 100644 d00491fd7e5bb6fa28c517a0bb32b8b506539d4d 2       foo

In other words, not porcelain at all.

"git ls-files -u" would be what you want.  It shows all the paths with
conflicts in the index, and omits paths without conflicts in the index.
And the object names allow you to inspect the individual stages.



I found out about that one too (by having a look at git-mergetool), and came up with the following quick hack (doesn't take any arguments/ options, is very rough and slow for a large number of conflicts). For each unmerged file it displays the file name, prefixed with the local and remote state. Possible states are "c" for created, "m" for modified and "d" for deleted. Probably there are other cases I'm not aware of and require special handling.

#!/bin/sh
# displays the merge status of files

# TODO all the niceties, bells and whistles...
USAGE=''
# requires PWD to be top-level
unset SUBDIRECTORY_OK
 . "$(git --exec-path)/git-sh-setup"
# obviously...
require_work_tree

# describe the state (deleted, modified or created)
describe_state () {
  mode="$1"

  if test -z "$mode"; then
    printf "d "
  else
    if test -n "$base_mode"; then
      printf "m "
    else
      printf "c "
    fi
  fi
}

# 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

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]