Bazaar renaming my file..

Ben Finney ben+bazaar at benfinney.id.au
Thu Nov 5 08:07:34 GMT 2009


Tata Dano <dano at i360connect.com> writes:

> I try to add a file on my branch with the same file on the main repo
> but when I commit it..it will produce a renamed file.

“Don't do that, then.”

With a VCS like Bazaar, you're tracking changes in the state of a
working tree. Once you've committed a file named ‘./bar.txt’, that is
*the* ‘./bar.txt’ for the branch, and its appearance in the working tree
is a change in state that is a unique event in the branch's history.

If the branch has recorded that the file currently named ‘./bar.txt’
appeared at a certain point in time, then it's a conflict if there is
now a *new* file that wants to have the same name. That's the conflict
Bazaar is reporting to you.

Either the new file has to go away, or you should be changing the
*existing* ‘./example.php’ in the branch to have the new contents that
you want, so that Bazaar knows it's the same file changing over time.

Here is my attempt to replicate your situation::

    $ bzr init trunk/
    Created a standalone tree (format: 2a)
    $ cd trunk/
    $ echo "Lorem ipsum dolor sit amet" > foo.txt
    $ bzr add
    adding foo.txt
    $ bzr commit --message "Initial commit of SpumCo project."
    Committing to: /home/bignose/Projects/foo/trunk/
    added foo.txt
    Committed revision 1.
    $ ls
    foo.txt

    $ cd ..
    $ bzr branch trunk/ feature-hummingbird/
    Branched 1 revision(s).
    $ bzr branch trunk/ feature-arbalest/
    Branched 1 revision(s).

    $ cd feature-arbalest/
    $ echo "Praesent at turpis justo, vitae lacinia lacus." > bar.txt
    $ bzr add
    adding bar.txt
    $ bzr commit --message "Begin work on Arbalest feature."
    Committing to: /home/bignose/Projects/foo/feature-arbalest/
    added bar.txt
    Committed revision 2.
    $ ls
    bar.txt  foo.txt

    $ cd ../trunk/
    $ ls
    foo.txt
    $ bzr merge ../feature-arbalest/
    +N  bar.txt
    All changes applied successfully.
    $ bzr commit --message "Merge current work on Arbalest feature."
    Committing to: /home/bignose/Projects/foo/trunk/
    added bar.txt
    Committed revision 2.
    $ ls
    bar.txt  foo.txt

    $ cd ../feature-hummingbird/
    $ ls
    foo.txt
    $ echo "Aliquam erat volutpat." > bar.txt   # Whoops!
    $ bzr add        # Now there's a *different* file ‘./bar.txt’, with
                     # no shared ancestry to the one currently in the
                     # trunk branch.
    adding bar.txt
    $ bzr commit --message "Begin work on Hummingbird feature."
    Committing to: /home/bignose/Projects/foo/feature-hummingbird/
    added bar.txt
    Committed revision 2.
    $ ls
    bar.txt  foo.txt

    $ bzr merge ../trunk/         # Asking for the changes from trunk
                                  # to be applied here.
    +N  bar.txt
    R   bar.txt => bar.txt.moved
    Conflict adding file bar.txt.  Moved existing file to bar.txt.moved.
    1 conflicts encountered.
    $ ls
    bar.txt  bar.txt.moved  foo.txt

So, the problem with that is my attempt to create a *separate* file
called ‘./bar.txt’, with no common ancestry to the one that exists in
the ‘trunk/’ branch; and then ask Bazaar to merge, which requires
merging the history of two files with the same name but no common
ancestry. Hence the conflict.

What should instead happen is this::

    $ ls
    foo.txt
    $ bzr merge ../trunk/
    +N  bar.txt
    All changes applied successfully.
    $ bzr commit --message "Merge from trunk/."
    Committing to: /home/bignose/Projects/foo/feature-hummingbird/
    added bar.txt
    Committed revision 2.
    $ ls
    bar.txt  foo.txt

    $ echo "Aliquam erat volutpat." > bar.txt
    $ bzr status
    modified:
      bar.txt
    $ bzr diff
    === modified file 'bar.txt'
    --- bar.txt     2009-11-05 07:39:47 +0000
    +++ bar.txt     2009-11-05 07:59:36 +0000
    @@ -1,1 +1,1 @@
    -Praesent at turpis justo, vitae lacinia lacus.
    +Aliquam erat volutpat.

    $ bzr commit --message "Begin work on Hummingbird feature."
    Committing to: /home/bignose/Projects/foo/feature-hummingbird/
    modified bar.txt
    Committed revision 3.
    $ ls
    bar.txt  foo.txt

That way, the file has a single point of origin (the revision originally
committed in the ‘feature-arbalest/’ branch, which has now propagated to
the others), and any further changes to its content can be tracked
consistently.

If you've already made (and committed) two files in separate branches
with the same name but no common ancestor, then you'll need to make a
choice: rename the file (since apparently it's served a different
purpose), or toss one of them altogether and make the desired changes to
the one that came from the trunk.

-- 
 \     “It is far better to grasp the universe as it really is than to |
  `\    persist in delusion, however satisfying and reassuring.” —Carl |
_o__)                                                            Sagan |
Ben Finney




More information about the bazaar mailing list