THIS IS A TEST INSTANCE ONLY! REPOSITORIES CAN BE DELETED AT ANY TIME!

Git Source Code Mirror - This is a publish-only repository and all pull requests are ignored. Please follow Documentation/SubmittingPatches procedure for any of your improvements.
git
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

168 lines
3.6KB

  1. #!/bin/sh
  2. #
  3. # Copyright (c) Linus Torvalds, 2005
  4. #
  5. # This is the git per-file merge script, called with
  6. #
  7. # $1 - original file SHA1 (or empty)
  8. # $2 - file in branch1 SHA1 (or empty)
  9. # $3 - file in branch2 SHA1 (or empty)
  10. # $4 - pathname in repository
  11. # $5 - original file mode (or empty)
  12. # $6 - file in branch1 mode (or empty)
  13. # $7 - file in branch2 mode (or empty)
  14. #
  15. # Handle some trivial cases.. The _really_ trivial cases have
  16. # been handled already by git read-tree, but that one doesn't
  17. # do any merges that might change the tree layout.
  18. USAGE='<orig blob> <our blob> <their blob> <path>'
  19. USAGE="$USAGE <orig mode> <our mode> <their mode>"
  20. LONG_USAGE="usage: git merge-one-file $USAGE
  21. Blob ids and modes should be empty for missing files."
  22. SUBDIRECTORY_OK=Yes
  23. . git-sh-setup
  24. cd_to_toplevel
  25. require_work_tree
  26. if test $# != 7
  27. then
  28. echo "$LONG_USAGE"
  29. exit 1
  30. fi
  31. case "${1:-.}${2:-.}${3:-.}" in
  32. #
  33. # Deleted in both or deleted in one and unchanged in the other
  34. #
  35. "$1.." | "$1.$1" | "$1$1.")
  36. if { test -z "$6" && test "$5" != "$7"; } ||
  37. { test -z "$7" && test "$5" != "$6"; }
  38. then
  39. echo "ERROR: File $4 deleted on one branch but had its" >&2
  40. echo "ERROR: permissions changed on the other." >&2
  41. exit 1
  42. fi
  43. if test -n "$2"
  44. then
  45. echo "Removing $4"
  46. else
  47. # read-tree checked that index matches HEAD already,
  48. # so we know we do not have this path tracked.
  49. # there may be an unrelated working tree file here,
  50. # which we should just leave unmolested. Make sure
  51. # we do not have it in the index, though.
  52. exec git update-index --remove -- "$4"
  53. fi
  54. if test -f "$4"
  55. then
  56. rm -f -- "$4" &&
  57. rmdir -p "$(expr "z$4" : 'z\(.*\)/')" 2>/dev/null || :
  58. fi &&
  59. exec git update-index --remove -- "$4"
  60. ;;
  61. #
  62. # Added in one.
  63. #
  64. ".$2.")
  65. # the other side did not add and we added so there is nothing
  66. # to be done, except making the path merged.
  67. exec git update-index --add --cacheinfo "$6" "$2" "$4"
  68. ;;
  69. "..$3")
  70. echo "Adding $4"
  71. if test -f "$4"
  72. then
  73. echo "ERROR: untracked $4 is overwritten by the merge." >&2
  74. exit 1
  75. fi
  76. git update-index --add --cacheinfo "$7" "$3" "$4" &&
  77. exec git checkout-index -u -f -- "$4"
  78. ;;
  79. #
  80. # Added in both, identically (check for same permissions).
  81. #
  82. ".$3$2")
  83. if test "$6" != "$7"
  84. then
  85. echo "ERROR: File $4 added identically in both branches," >&2
  86. echo "ERROR: but permissions conflict $6->$7." >&2
  87. exit 1
  88. fi
  89. echo "Adding $4"
  90. git update-index --add --cacheinfo "$6" "$2" "$4" &&
  91. exec git checkout-index -u -f -- "$4"
  92. ;;
  93. #
  94. # Modified in both, but differently.
  95. #
  96. "$1$2$3" | ".$2$3")
  97. case ",$6,$7," in
  98. *,120000,*)
  99. echo "ERROR: $4: Not merging symbolic link changes." >&2
  100. exit 1
  101. ;;
  102. *,160000,*)
  103. echo "ERROR: $4: Not merging conflicting submodule changes." >&2
  104. exit 1
  105. ;;
  106. esac
  107. src1=$(git unpack-file $2)
  108. src2=$(git unpack-file $3)
  109. case "$1" in
  110. '')
  111. echo "Added $4 in both, but differently."
  112. orig=$(git unpack-file $(git hash-object /dev/null))
  113. ;;
  114. *)
  115. echo "Auto-merging $4"
  116. orig=$(git unpack-file $1)
  117. ;;
  118. esac
  119. git merge-file "$src1" "$orig" "$src2"
  120. ret=$?
  121. msg=
  122. if test $ret != 0 || test -z "$1"
  123. then
  124. msg='content conflict'
  125. ret=1
  126. fi
  127. # Create the working tree file, using "our tree" version from the
  128. # index, and then store the result of the merge.
  129. git checkout-index -f --stage=2 -- "$4" && cat "$src1" >"$4" || exit 1
  130. rm -f -- "$orig" "$src1" "$src2"
  131. if test "$6" != "$7"
  132. then
  133. if test -n "$msg"
  134. then
  135. msg="$msg, "
  136. fi
  137. msg="${msg}permissions conflict: $5->$6,$7"
  138. ret=1
  139. fi
  140. if test $ret != 0
  141. then
  142. echo "ERROR: $msg in $4" >&2
  143. exit 1
  144. fi
  145. exec git update-index -- "$4"
  146. ;;
  147. *)
  148. echo "ERROR: $4: Not handling case $1 -> $2 -> $3" >&2
  149. ;;
  150. esac
  151. exit 1