[git-users] Re: Merge conflict following submodule move
Instead of figuring out why renames of submodules are not detected by git merge, I worked around the issue by writing a script to delete and re-add the submodule separately in the maintenance and development branches: #!/bin/bash -ex # -e: Exit on error # -x: Print commands as they are executed # move_submodule: Move a submodule in a development branch while keeping # it in the same location in a maintenance branch. If git mv is used to # move the submodule instead, there will be a merge conflict every time # changes are merged up to the development branch from the maintenance # branch. This script works by deleting the submodule and then readding # it separately in both branches. If git mv has already been attempted, # the moved submodule is also deleted. if [ $# -ne 5 ]; then echo $0: usage: $0 maintenance_branch development_branch submodule_url old_path new_path exit 1 fi maintenance=$1 development=$2 submodule_url=$3 old_path=$4 new_path=$5 repository=`git rev-parse --show-toplevel` cd $repository # Get branches ready git checkout $maintenance git pull git checkout $development git pull git submodule update --init --recursive git merge $maintenance --no-edit git push # Delete submodule in $development if you already moved it with git mv. if [ -d "$new_path" ]; then git rm $new_path git commit -m"Remove $new_path temporarily to resolve conflict with $maintenance." git push fi # Delete submodule in $maintenance and merge up. git checkout $maintenance git submodule update --init --recursive git rm $old_path git commit -m"Remove $old_path temporarily to resolve conflict with $development." git push git checkout $development git submodule update --init --recursive git merge $maintenance --no-edit git push # Re-add submodule in new location in $development. git submodule add --force $submodule_url $new_path git commit -m"Re-add $new_path" git push # Re-add submodule in original location in $maintenance. git checkout $maintenance rm -rf $new_path git submodule update --init --recursive git submodule add --force $submodule_url $old_path git commit -m"Re-add $old_path." git push # Merge up, discarding maintenance submodule change. git checkout $development rm -rf $old_path git submodule update --init --recursive git merge $maintenance --no-edit -s ours git push On Tuesday, July 10, 2018 at 12:51:48 PM UTC-5, waxline wrote: > > After moving a submodule in a development branch, I get a merge conflict > every time I merge changes up from the master branch. To resolve, I must git > add mysubmodule. How can I avoid resolving this conflict every time I > merge up? Here is a script which illustrates the problem: > > cd ~/src > git init MyProduct > git init MySubmodule > cd MySubmodule > echo "foo" > foo.txt > git add foo.txt > git commit -m "Add foo.txt" > cd ../MyProduct > echo "bar" > bar.txt > git add bar.txt > git commit -m "Add bar.txt" > git submodule add ../MySubmodule > git commit -m "Add MySubmodule" > git branch development > git checkout development > git mv MySubmodule OurSubmodule > git commit -m "Move MySubmodule to OurSubmodule." > git checkout master > rm -rf OurSubmodule > git submodule update --init > echo "barbar" > bar.txt > git commit -am"Update bar.txt" > git checkout development > rm -rf MySubmodule > git submodule update --init > git merge master > git add OurSubmodule > git commit -am"Resolve conflict" > > > -- You received this message because you are subscribed to the Google Groups "Git for human beings" group. To unsubscribe from this group and stop receiving emails from it, send an email to git-users+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: [git-users] Git Hooks: How to access the files?
On Wed, Jul 11, 2018 at 02:53:37PM +0200, Jochen Wiedmann wrote: [...] > Is it possible for me to distinguish between a "bare repository" and > the "root of a working tree"? Uh, this is an apples to oranges comparison: a bare repository has no work tree, and a regular repository consists of a work tree and a directory named ".git" and containing the Git object database inside it. So, is your question should instead be read as "how do I tell whether my hook runs in a bare or in a normal repository"? If yes, let's instead start with discussing what type of hook you intend to run; otherwise we may be dragged away by discussing a non-issue (search for the "XY problem" on the 'net). -- You received this message because you are subscribed to the Google Groups "Git for human beings" group. To unsubscribe from this group and stop receiving emails from it, send an email to git-users+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: [git-users] Git Hooks: How to access the files?
Thanks, Konstantin, I'll give your suggestion a try. One followup question, though: Is it possible for me to distinguish between a "bare repository" and the "root of a working tree"? Jochen On Wed, Jul 11, 2018 at 2:44 PM Konstantin Khomoutov wrote: > > On Wed, Jul 11, 2018 at 04:37:25AM -0700, Jochen Wiedmann wrote: > > > I have studied a lot of Git hooks, both simple ones (like the ones, that > > can be found in the "hooks" directory), as well as more complex ones (like > > those running checkstyle), but one question remains unanswered: > > > > Assuming, my git hooks directory is "": Can I > > simply use "../../relative_path_to_file" to access a file in my project > > directory? (The intention being to validate the projects contents in a > > pre-commit, or pre-push hook.) > > Depends on the kind of hook. > > Some hooks are defined to run in the work tree of a non-bare repository. > Namely, hooks which have "commit", "rebase", "patch" etc in their names > are of this kind. > > Still, you should not assume where your Git worktree is located the way > you supposed: Git does some setup before calling its hooks - to cite the > githooks(5) manual: > > | Before Git invokes a hook, it changes its working directory to > | either the root of the working tree in a non-bare repository, or to the > | $GIT_DIR in a bare repository. > > So, when a work-tree related hook runs, the current directory of the > process executing the hook will be the work tree already. > > > More hard-core hooks — such as "[pre-]receive", "[pre-|post-]update" etc > typically run in a server-side bare repository which does not have a > work tree attached. For this kind of hooks, inspecting individual files > is still possible but requires usage of low-level (so-called "plumbing") > Git commands which are able to access the object database of a > repository directly. If you need this, ask a more precise question, and > we will try to help. > > -- > You received this message because you are subscribed to a topic in the Google > Groups "Git for human beings" group. > To unsubscribe from this topic, visit > https://groups.google.com/d/topic/git-users/3sHmGC0IpC8/unsubscribe. > To unsubscribe from this group and all its topics, send an email to > git-users+unsubscr...@googlegroups.com. > For more options, visit https://groups.google.com/d/optout. -- You received this message because you are subscribed to the Google Groups "Git for human beings" group. To unsubscribe from this group and stop receiving emails from it, send an email to git-users+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: [git-users] Git Hooks: How to access the files?
On Wed, Jul 11, 2018 at 04:37:25AM -0700, Jochen Wiedmann wrote: > I have studied a lot of Git hooks, both simple ones (like the ones, that > can be found in the "hooks" directory), as well as more complex ones (like > those running checkstyle), but one question remains unanswered: > > Assuming, my git hooks directory is "": Can I > simply use "../../relative_path_to_file" to access a file in my project > directory? (The intention being to validate the projects contents in a > pre-commit, or pre-push hook.) Depends on the kind of hook. Some hooks are defined to run in the work tree of a non-bare repository. Namely, hooks which have "commit", "rebase", "patch" etc in their names are of this kind. Still, you should not assume where your Git worktree is located the way you supposed: Git does some setup before calling its hooks - to cite the githooks(5) manual: | Before Git invokes a hook, it changes its working directory to | either the root of the working tree in a non-bare repository, or to the | $GIT_DIR in a bare repository. So, when a work-tree related hook runs, the current directory of the process executing the hook will be the work tree already. More hard-core hooks — such as "[pre-]receive", "[pre-|post-]update" etc typically run in a server-side bare repository which does not have a work tree attached. For this kind of hooks, inspecting individual files is still possible but requires usage of low-level (so-called "plumbing") Git commands which are able to access the object database of a repository directly. If you need this, ask a more precise question, and we will try to help. -- You received this message because you are subscribed to the Google Groups "Git for human beings" group. To unsubscribe from this group and stop receiving emails from it, send an email to git-users+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
[git-users] Git Hooks: How to access the files?
Hi, I have studied a lot of Git hooks, both simple ones (like the ones, that can be found in the "hooks" directory), as well as more complex ones (like those running checkstyle), but one question remains unanswered: Assuming, my git hooks directory is "": Can I simply use "../../relative_path_to_file" to access a file in my project directory? (The intention being to validate the projects contents in a pre-commit, or pre-push hook.) Thanks, Jochen -- You received this message because you are subscribed to the Google Groups "Git for human beings" group. To unsubscribe from this group and stop receiving emails from it, send an email to git-users+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.