2

When I work with somebody on the Qt project we always have conflicts in .pro files.

For example there is such project tree

HEADERS += \
main.cpp \
a.cpp

I add new file b.cpp in Qt Creator while somebody adds c.cpp. In the result I have new .pro file

HEADERS += \
main.cpp \
a.cpp \
b.cpp

And my colleague has file

HEADERS += \
main.cpp \
a.cpp \
c.cpp

When we both commit changes our project files will be in conflict. What is the right way to configure Qt Creator or git to normally merge this stuff into:

HEADERS += \
main.cpp \
a.cpp \
b.cpp \
c.cpp
Seagull
  • 3,319
  • 2
  • 31
  • 37
  • Is .pro a file, that can be ignore while committing changes? What I mean is, is it a file generated because of build process. – robert Sep 28 '13 at 15:07
  • 1
    No, .pro is the project file, it's part of the sources. It should be versioned and should not be ignored. – Pavel Strakhov Sep 28 '13 at 15:09

5 Answers5

1

First of all, merge conflicts are managed not by Qt Creator but by the version control system. So you can't say "configure Qt Creator to normally merge this stuff". It's the VCS that you need to configure.

However, you can use wildcards in pro files as described in this answer. In this configuration you don't need to modify .pro file when adding new files, so the VCS will be calm about it.

Community
  • 1
  • 1
Pavel Strakhov
  • 39,123
  • 5
  • 88
  • 127
  • I am convinced that if Qt Creator will add slash \ at the end of each line VCS will be able to merge easy cases. Or Qt Creator may arrange the files in alphabetic order which also may help. – Seagull Sep 28 '13 at 16:20
1

You could try using wildcards to avoid having to frequently change the .pro or .pri files.

HEADERS += $$files(*.h)
SOURCES += $$files(*.cpp)

Note, in a .pri you'll want to prefix the path with $$PWD because otherwise the paths are relative to the location of the .pro.

HEADERS += $$files($$PWD/*.h)
SOURCES += $$files($$PWD/*.cpp)
Leif Gruenwoldt
  • 13,561
  • 5
  • 60
  • 64
0

Set some "add/remove file" rules for your team to reduce conflict.

The simple one: If you guys are physically near, a team member can always inform others first before adding/removing files.

The other one is setting the following rule when "adding files":

  1. Before a member wants to add files, she must commit her changes first.
  2. Then she would pull changes from master. If others have added files, she would now have the latest .pro file.
  3. Add the files.
  4. Quickly commit and push to master.

Of course she may still get unlucky if others adds files after step 2 and before step 4.

fxam
  • 3,874
  • 1
  • 22
  • 32
  • I think, before pushing one must pull changes from master. Otherwise your push will be rejected, if there has been another push in the remote before. – robert Sep 28 '13 at 15:49
  • The power of VCS is in convenient automatic merging. The described algorithm is a workaround for the problem, but it's hardly convenient. You can avoid merging conflicts at all if you always act like described, but it will make using VCS almost pointless. – Pavel Strakhov Sep 28 '13 at 16:35
0

i think you can add each file manually or edit pro file after appending using the next notation

HEADERS += header1.h
HEADERS += header2.h
HEADERS += header3.h

but i dont know way how to say to qt creator use this approach

0

The problem is that both you and your colleague are changing the "a.cpp" line, and your VC system doesn't figure out you've both done the same thing as the change is typically lumped with the different change on the following line.

I haven't found a way to configure Qt QCreator to do this but one way of avoiding the specific conflicts your are experiencing is to always add the "\" at the end of the line even for the last item in the list, and then leave two blank lines after the list. e.g.

Original .pro:

HEADERS += \
main.cpp \
a.cpp \


# other stuff

Your new .pro:

HEADERS += \
main.cpp \
a.cpp \
b.cpp \


# other stuff

Then if your colleague commits:

HEADERS += \
main.cpp \
a.cpp \
c.cpp \

# other stuff

Then your VC system should normally resolve the conflict with no help.

I also recommend keeping these .pro file lists (SOURCES=, RESOURCES= etc.) sorted alphabetically, as it helps with keeping the VC commit history easier to understand, and since there seems no way to configure Qt QCreator to do this I tend to always just add new files by editing the .pro in text mode. That way, I find I always have control over what happens. If you're not a control freak like me and find clicking through a bunch of GUI file-browser-ish things liberating (as apposed to annoying), you can first use the GUI stuff and then open the .pro in text mode and tidy the .pro file up after making your changes, but before doing any commits.

user6092647
  • 1,031
  • 9
  • 8